Why do buttons have a black outline?

Discussion in 'Microsoft Dot NET Framework Forms' started by seguso, Jul 12, 2007.

  1. seguso

    seguso Guest

    Hello,

    In my application, I am drawing some pushbuttons with
    VisualStyleRenderer, but the buttons appear with a black outline.
    Could someone please tell me why?

    Here is a picture of the black outline:

    http://picasaweb.google.com/maurizio.colucci/Demo/photo#5086249187839415826

    Additional informations:

    I am using Visual Studio 2005. The code I am using to draw buttons is

    Dim renderer_normal As VisualStyleRenderer
    renderer_normal = New
    VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    [..]
    renderer_normal.DrawBackground(gr, rect) ' gr is a Graphics object
    and rect is a Rectangle

    I am drawing on a backbuffer (double buffering). I am clearing the
    backbuffer with white before drawing the buttons, but the black
    outline appears nevertheless.

    Also, when I draw disabled buttons, they don't have a black outline
    (see picture).

    Thanks for any help

    Maurizio
     
    seguso, Jul 12, 2007
    #1
    1. Advertisements

  2. seguso

    Mr. Arnold Guest

    "seguso" <> wrote in message
    news:...
    > Hello,
    >
    > In my application, I am drawing some pushbuttons with
    > VisualStyleRenderer, but the buttons appear with a black outline.
    > Could someone please tell me why?


    Maybe, because black is a neutral color and is more easy to see, by some
    users.

    >
    > Also, when I draw disabled buttons, they don't have a black outline


    Because that's an indication that the button is disabled, which again is a
    neutral color of gray, so that it's easy to see by some users.
     
    Mr. Arnold, Jul 12, 2007
    #2
    1. Advertisements

  3. seguso

    seguso Guest

    On 12 Lug, 13:33, "Mr. Arnold" <MR. > wrote:
    > "seguso" <> wrote in message
    >
    > news:...
    >
    > > Hello,

    >
    > > In my application, I am drawing some pushbuttons with
    > > VisualStyleRenderer, but the buttons appear with a black outline.
    > > Could someone please tell me why?

    >
    > Maybe, because black is a neutral color and is more easy to see, by some
    > users.


    Then why do ordinary buttons in Windows Forms not have such an
    outline?


    > > Also, when I draw disabled buttons, they don't have a black outline

    >
    > Because that's an indication that the button is disabled, which again is a
    > neutral color of gray, so that it's easy to see by some users.


    So there is no way to remove the outline? :(

    Thanks

    Maurizio
     
    seguso, Jul 12, 2007
    #3
  4. seguso

    Mick Doherty Guest

    Use the VisualStylesRenderers DrawParentBackground() method before the
    DrawBackground() method.

    Although if you are clearing with white before drawing the button, then you
    should have a white border and not a black one.

    Where do you get the Graphics Object from?

    --
    Mick Doherty
    http://www.dotnetrix.co.uk/nothing.html


    "seguso" <> wrote in message
    news:...
    > Hello,
    >
    > In my application, I am drawing some pushbuttons with
    > VisualStyleRenderer, but the buttons appear with a black outline.
    > Could someone please tell me why?
    >
    > Here is a picture of the black outline:
    >
    >
    > http://picasaweb.google.com/maurizio.colucci/Demo/photo#5086249187839415826
    >
    > Additional informations:
    >
    > I am using Visual Studio 2005. The code I am using to draw buttons is
    >
    > Dim renderer_normal As VisualStyleRenderer
    > renderer_normal = New
    > VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    > [..]
    > renderer_normal.DrawBackground(gr, rect) ' gr is a Graphics object
    > and rect is a Rectangle
    >
    > I am drawing on a backbuffer (double buffering). I am clearing the
    > backbuffer with white before drawing the buttons, but the black
    > outline appears nevertheless.
    >
    > Also, when I draw disabled buttons, they don't have a black outline
    > (see picture).
    >
    > Thanks for any help
    >
    > Maurizio
    >
     
    Mick Doherty, Jul 12, 2007
    #4
  5. seguso

    seguso Guest

    On 12 Lug, 15:54, "Mick Doherty"
    <EXCHANGE#.[mdaudi100#ntlworld.com]>
    wrote:
    > Use the VisualStylesRenderers DrawParentBackground() method before the
    > DrawBackground() method.


    Interesting though, as you say, I am clearing with white.

    > Where do you get the Graphics Object from?


    Thank you very much Mick. Here is the relevant part of the code. I am
    using double buffer. I am overriding onPaint and onPaintBackground().
    I am leaving onPaintBackground empty, and I am doing all the drawing
    in onPaint.


    Private Sub drawMe()

    _backBuffer = New Bitmap(Me.Width, Me.Height)

    Dim gr As Graphics = Graphics.FromImage(_backBuffer)

    Dim renderer_normal As VisualStyleRenderer
    renderer_normal = New
    VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)

    ' fill with white
    gr.FillRectangle(New
    SolidBrush(Color.FromKnownColor(KnownColor.White)), New Rectangle(0,
    0, Me.Width, Me.Height))

    ' [..] set up the rectangle, etc.

    renderer_normal.DrawBackground(gr, r)

    ' [..]

    gr.Dispose()
    Me.CreateGraphics.DrawImageUnscaled(_backBuffer, 0, 0)


    End Sub


    private _backBuffer as Bitmap

    Protected Overrides Sub OnPaint(ByVal e As
    System.Windows.Forms.PaintEventArgs)
    drawMe()

    End Sub

    Protected Overrides Sub OnPaintBackground(ByVal pevent As
    System.Windows.Forms.PaintEventArgs)
    ' empty
    End Sub
     
    seguso, Jul 12, 2007
    #5
  6. seguso

    seguso Guest

    Never mind! I solved by using a newer technique for double buffering
    (see below). Thank you very much!


    private sub drawMe()

    Dim currentContext As BufferedGraphicsContext
    Dim myBuffer As BufferedGraphics

    currentContext = BufferedGraphicsManager.Current
    myBuffer = currentContext.Allocate(Me.CreateGraphics,
    Me.DisplayRectangle)

    Dim gr As Graphics
    gr = myBuffer.Graphics

    gr.FillRectangle(New
    SolidBrush(Color.FromKnownColor(KnownColor.ControlLightLight)), New
    Rectangle(0, 0, Me.Width, Me.Height))

    Dim renderer_normal As VisualStyleRenderer
    renderer_normal = New
    VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)

    renderer_normal.DrawBackground(gr, r_top)

    myBuffer.Render()

    end sub
     
    seguso, Jul 12, 2007
    #6
  7. seguso

    pz pz Guest

    Re: Never mind!

    Change fore color propery of button and see outline of it
    :)

    > On Thursday, July 12, 2007 6:11 AM seguso wrote:


    > Hello,
    >
    > In my application, I am drawing some pushbuttons with
    > VisualStyleRenderer, but the buttons appear with a black outline.
    > Could someone please tell me why?
    >
    > Here is a picture of the black outline:
    >
    > http://picasaweb.google.com/maurizio.colucci/Demo/photo#5086249187839415826
    >
    > Additional informations:
    >
    > I am using Visual Studio 2005. The code I am using to draw buttons is
    >
    > Dim renderer_normal As VisualStyleRenderer
    > renderer_normal = New
    > VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    > [..]
    > renderer_normal.DrawBackground(gr, rect) ' gr is a Graphics object
    > and rect is a Rectangle
    >
    > I am drawing on a backbuffer (double buffering). I am clearing the
    > backbuffer with white before drawing the buttons, but the black
    > outline appears nevertheless.
    >
    > Also, when I draw disabled buttons, they don't have a black outline
    > (see picture).
    >
    > Thanks for any help
    >
    > Maurizio



    >> On Thursday, July 12, 2007 7:33 AM Mr. Arnold wrote:


    >> "seguso" <> wrote in message
    >> news:...
    >>
    >> Maybe, because black is a neutral color and is more easy to see, by some
    >> users.
    >>
    >>
    >> Because that's an indication that the button is disabled, which again is a
    >> neutral color of gray, so that it's easy to see by some users.



    >>> On Thursday, July 12, 2007 8:30 AM seguso wrote:


    >>> Then why do ordinary buttons in Windows Forms not have such an
    >>> outline?
    >>>
    >>>
    >>>
    >>> So there is no way to remove the outline? :(
    >>>
    >>> Thanks
    >>>
    >>> Maurizio



    >>>> On Thursday, July 12, 2007 9:54 AM Mick Doherty wrote:


    >>>> Use the VisualStylesRenderers DrawParentBackground() method before the
    >>>> DrawBackground() method.
    >>>>
    >>>> Although if you are clearing with white before drawing the button, then you
    >>>> should have a white border and not a black one.
    >>>>
    >>>> Where do you get the Graphics Object from?
    >>>>
    >>>> --
    >>>> Mick Doherty
    >>>> http://www.dotnetrix.co.uk/nothing.html
    >>>>
    >>>>
    >>>> "seguso" <> wrote in message
    >>>> news:...



    >>>>> On Thursday, July 12, 2007 10:07 AM seguso wrote:


    >>>>> On 12 Lug, 15:54, "Mick Doherty"
    >>>>> <EXCHANGE#.[mdaudi100#ntlworld.com]>
    >>>>> wrote:
    >>>>>
    >>>>> Interesting though, as you say, I am clearing with white.
    >>>>>
    >>>>>
    >>>>> Thank you very much Mick. Here is the relevant part of the code. I am
    >>>>> using double buffer. I am overriding onPaint and onPaintBackground().
    >>>>> I am leaving onPaintBackground empty, and I am doing all the drawing
    >>>>> in onPaint.
    >>>>>
    >>>>>
    >>>>> Private Sub drawMe()
    >>>>>
    >>>>> _backBuffer = New Bitmap(Me.Width, Me.Height)
    >>>>>
    >>>>> Dim gr As Graphics = Graphics.FromImage(_backBuffer)
    >>>>>
    >>>>> Dim renderer_normal As VisualStyleRenderer
    >>>>> renderer_normal = New
    >>>>> VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    >>>>>
    >>>>> ' fill with white
    >>>>> gr.FillRectangle(New
    >>>>> SolidBrush(Color.FromKnownColor(KnownColor.White)), New Rectangle(0,
    >>>>> 0, Me.Width, Me.Height))
    >>>>>
    >>>>> ' [..] set up the rectangle, etc.
    >>>>>
    >>>>> renderer_normal.DrawBackground(gr, r)
    >>>>>
    >>>>> ' [..]
    >>>>>
    >>>>> gr.Dispose()
    >>>>> Me.CreateGraphics.DrawImageUnscaled(_backBuffer, 0, 0)
    >>>>>
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>>
    >>>>> private _backBuffer as Bitmap
    >>>>>
    >>>>> Protected Overrides Sub OnPaint(ByVal e As
    >>>>> System.Windows.Forms.PaintEventArgs)
    >>>>> drawMe()
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>> Protected Overrides Sub OnPaintBackground(ByVal pevent As
    >>>>> System.Windows.Forms.PaintEventArgs)
    >>>>> ' empty
    >>>>> End Sub



    >>>>>> On Thursday, July 12, 2007 10:41 AM seguso wrote:


    >>>>>> Never mind! I solved by using a newer technique for double buffering
    >>>>>> (see below). Thank you very much!
    >>>>>>
    >>>>>>
    >>>>>> private sub drawMe()
    >>>>>>
    >>>>>> Dim currentContext As BufferedGraphicsContext
    >>>>>> Dim myBuffer As BufferedGraphics
    >>>>>>
    >>>>>> currentContext = BufferedGraphicsManager.Current
    >>>>>> myBuffer = currentContext.Allocate(Me.CreateGraphics,
    >>>>>> Me.DisplayRectangle)
    >>>>>>
    >>>>>> Dim gr As Graphics
    >>>>>> gr = myBuffer.Graphics
    >>>>>>
    >>>>>> gr.FillRectangle(New
    >>>>>> SolidBrush(Color.FromKnownColor(KnownColor.ControlLightLight)), New
    >>>>>> Rectangle(0, 0, Me.Width, Me.Height))
    >>>>>>
    >>>>>> Dim renderer_normal As VisualStyleRenderer
    >>>>>> renderer_normal = New
    >>>>>> VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    >>>>>>
    >>>>>> renderer_normal.DrawBackground(gr, r_top)
    >>>>>>
    >>>>>> myBuffer.Render()
    >>>>>>
    >>>>>> end sub



    >>>>>> Submitted via EggHeadCafe
    >>>>>> Microsoft SQL Server DBA For Beginners
    >>>>>> http://www.eggheadcafe.com/training-topic-area/SQL-Server-DBA/6/SQL-Server-DBA.aspx
     
    pz pz, Jan 1, 2011
    #7
  8. seguso

    pz pz Guest

    Change fore color property of button and see outline of button :)

    > On Thursday, July 12, 2007 6:11 AM seguso wrote:


    > Hello,
    >
    > In my application, I am drawing some pushbuttons with
    > VisualStyleRenderer, but the buttons appear with a black outline.
    > Could someone please tell me why?
    >
    > Here is a picture of the black outline:
    >
    > http://picasaweb.google.com/maurizio.colucci/Demo/photo#5086249187839415826
    >
    > Additional informations:
    >
    > I am using Visual Studio 2005. The code I am using to draw buttons is
    >
    > Dim renderer_normal As VisualStyleRenderer
    > renderer_normal = New
    > VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    > [..]
    > renderer_normal.DrawBackground(gr, rect) ' gr is a Graphics object
    > and rect is a Rectangle
    >
    > I am drawing on a backbuffer (double buffering). I am clearing the
    > backbuffer with white before drawing the buttons, but the black
    > outline appears nevertheless.
    >
    > Also, when I draw disabled buttons, they don't have a black outline
    > (see picture).
    >
    > Thanks for any help
    >
    > Maurizio



    >> On Thursday, July 12, 2007 7:33 AM Mr. Arnold wrote:


    >> "seguso" <> wrote in message
    >> news:...
    >>
    >> Maybe, because black is a neutral color and is more easy to see, by some
    >> users.
    >>
    >>
    >> Because that's an indication that the button is disabled, which again is a
    >> neutral color of gray, so that it's easy to see by some users.



    >>> On Thursday, July 12, 2007 8:30 AM seguso wrote:


    >>> Then why do ordinary buttons in Windows Forms not have such an
    >>> outline?
    >>>
    >>>
    >>>
    >>> So there is no way to remove the outline? :(
    >>>
    >>> Thanks
    >>>
    >>> Maurizio



    >>>> On Thursday, July 12, 2007 9:54 AM Mick Doherty wrote:


    >>>> Use the VisualStylesRenderers DrawParentBackground() method before the
    >>>> DrawBackground() method.
    >>>>
    >>>> Although if you are clearing with white before drawing the button, then you
    >>>> should have a white border and not a black one.
    >>>>
    >>>> Where do you get the Graphics Object from?
    >>>>
    >>>> --
    >>>> Mick Doherty
    >>>> http://www.dotnetrix.co.uk/nothing.html
    >>>>
    >>>>
    >>>> "seguso" <> wrote in message
    >>>> news:...



    >>>>> On Thursday, July 12, 2007 10:07 AM seguso wrote:


    >>>>> On 12 Lug, 15:54, "Mick Doherty"
    >>>>> <EXCHANGE#.[mdaudi100#ntlworld.com]>
    >>>>> wrote:
    >>>>>
    >>>>> Interesting though, as you say, I am clearing with white.
    >>>>>
    >>>>>
    >>>>> Thank you very much Mick. Here is the relevant part of the code. I am
    >>>>> using double buffer. I am overriding onPaint and onPaintBackground().
    >>>>> I am leaving onPaintBackground empty, and I am doing all the drawing
    >>>>> in onPaint.
    >>>>>
    >>>>>
    >>>>> Private Sub drawMe()
    >>>>>
    >>>>> _backBuffer = New Bitmap(Me.Width, Me.Height)
    >>>>>
    >>>>> Dim gr As Graphics = Graphics.FromImage(_backBuffer)
    >>>>>
    >>>>> Dim renderer_normal As VisualStyleRenderer
    >>>>> renderer_normal = New
    >>>>> VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    >>>>>
    >>>>> ' fill with white
    >>>>> gr.FillRectangle(New
    >>>>> SolidBrush(Color.FromKnownColor(KnownColor.White)), New Rectangle(0,
    >>>>> 0, Me.Width, Me.Height))
    >>>>>
    >>>>> ' [..] set up the rectangle, etc.
    >>>>>
    >>>>> renderer_normal.DrawBackground(gr, r)
    >>>>>
    >>>>> ' [..]
    >>>>>
    >>>>> gr.Dispose()
    >>>>> Me.CreateGraphics.DrawImageUnscaled(_backBuffer, 0, 0)
    >>>>>
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>>
    >>>>> private _backBuffer as Bitmap
    >>>>>
    >>>>> Protected Overrides Sub OnPaint(ByVal e As
    >>>>> System.Windows.Forms.PaintEventArgs)
    >>>>> drawMe()
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>> Protected Overrides Sub OnPaintBackground(ByVal pevent As
    >>>>> System.Windows.Forms.PaintEventArgs)
    >>>>> ' empty
    >>>>> End Sub



    >>>>>> On Thursday, July 12, 2007 10:41 AM seguso wrote:


    >>>>>> Never mind! I solved by using a newer technique for double buffering
    >>>>>> (see below). Thank you very much!
    >>>>>>
    >>>>>>
    >>>>>> private sub drawMe()
    >>>>>>
    >>>>>> Dim currentContext As BufferedGraphicsContext
    >>>>>> Dim myBuffer As BufferedGraphics
    >>>>>>
    >>>>>> currentContext = BufferedGraphicsManager.Current
    >>>>>> myBuffer = currentContext.Allocate(Me.CreateGraphics,
    >>>>>> Me.DisplayRectangle)
    >>>>>>
    >>>>>> Dim gr As Graphics
    >>>>>> gr = myBuffer.Graphics
    >>>>>>
    >>>>>> gr.FillRectangle(New
    >>>>>> SolidBrush(Color.FromKnownColor(KnownColor.ControlLightLight)), New
    >>>>>> Rectangle(0, 0, Me.Width, Me.Height))
    >>>>>>
    >>>>>> Dim renderer_normal As VisualStyleRenderer
    >>>>>> renderer_normal = New
    >>>>>> VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal)
    >>>>>>
    >>>>>> renderer_normal.DrawBackground(gr, r_top)
    >>>>>>
    >>>>>> myBuffer.Render()
    >>>>>>
    >>>>>> end sub



    >>>>>>> On Saturday, January 01, 2011 3:34 AM pz pz wrote:


    >>>>>>> Change fore color propery of button and see outline of it
    >>>>>>>
    >>>>>>> :)



    >>>>>>> Submitted via EggHeadCafe
    >>>>>>> Microsoft Silverlight For Beginners
    >>>>>>> http://www.eggheadcafe.com/training-topic-area/Microsoft-Silverlight/10/Silverlight.aspx
     
    pz pz, Jan 1, 2011
    #8
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page