Why does Button.ForeColor change button's border ?

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Hello,

Surely I'm missing something obvious.

How do you change a button's text color without causing a change to the
button's border?

The following line of code causes the button to be drawn with a yellow
border:
btnTest.ForeColor = Color.Yellow;

Thanks, Jeff
 
Jeff said:
How do you change a button's text color without causing a change to the
button's border?

The following line of code causes the button to be drawn with a yellow
border:
btnTest.ForeColor = Color.Yellow;

Is your button's 'FlatStyle' property set to 'Flat'?
 
Hello Herfried,

Yes, I've tried Flat.

In fact, all of the FlatStyles have this border issue.

Thanks for your input, Jeff
 
Hi Jeff,

Thanks for your posting!

Yes, I have reproduced out this issue. Actually, the border will only use
the forecolor to draw it when the button has focus.
This is by design. Does this affect you much, and you have concern on it?

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Jeffrey,

Thanks for helping out.

You are correct. The simple test case only shows the border on the button
with focus.
Not sure why my form with lots of buttons shows this border on every button?

Anyhow, I was able to override Button.OnPaint( ) and use
ControlPaint.DrawBorder( ) to eliminate
this ForeColor border on every button. Basically, I draw over it with the
form background color.

Now, I'm down to just figuring out how to eliminate the focus
rectangle/border on the button with focus.
I've tried ControlPaint.DrawFocusRectangle, but no luck.

Regards, Jeff
 
Hi Jeff,

Thanks very much for your feedback!

But, based on my test, if we override the OnPaint method, and draw the
border ourselves, event in focus mode, the forecolor will not affect the
border.

Code snippet lists below:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
ControlPaint.DrawBorder3D( e.Graphics, this.ClientRectangle,
System.Windows.Forms.Border3DStyle.Raised );
}

Does this meet your need? If you still have problem on it, I suggest you
send a reproduce sample project to me to reproduce out. Then I will help
you better.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
You are welcome!! If you need further help, please feel free to tell me, I
am glad to work with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top