Why do buttons have a black outline?

  • Thread starter Thread starter seguso
  • Start date Start date
S

seguso

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 said:
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.
 
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?

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
 
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?
 
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
 
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
 
Change fore color propery of button and see outline of it
:)
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:

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.
54, "Mick Doherty"
<EXCHANGE#[email protected].[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
 
Change fore color property of button and see outline of button :)
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:

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.
54, "Mick Doherty"
<EXCHANGE#[email protected].[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
 
Back
Top