I set the Button Winforms control properties so that they appear as a hyperlink on a web page. I formatted everything perfectly, except for the border of the FlatAppearance object. I have code that acts like pseudo-CSS (FormBackColor is a string constant.):
b.FlatStyle = FlatStyle.Flat b.BackColor = ColorTranslator.FromHtml(FormBackColor) b.ForeColor = Color.Blue b.Font = New Font(b.Font.FontFamily, b.Font.Size, FontStyle.Underline) b.Cursor = Cursors.Hand Dim fa As FlatButtonAppearance = b.FlatAppearance fa.BorderSize = 0 fa.MouseOverBackColor = b.BackColor fa.MouseDownBackColor = b.BackColor AddHandler b.MouseEnter, AddressOf ButtonMouseOver AddHandler b.MouseLeave, AddressOf ButtonMouseOut
Here are the mouse / add-in functions as a reference to what happens:
Public Shared Sub ButtonMouseOver(ByVal sender As Object, ByVal e As EventArgs) Dim b As Button = DirectCast(sender, Button) Dim fa As FlatButtonAppearance = b.FlatAppearance fa.BorderSize = 1 End Sub Public Shared Sub ButtonMouseOut(ByVal sender As Object, ByVal e As EventArgs) Dim b As Button = DirectCast(sender, Button) Dim fa As FlatButtonAppearance = b.FlatAppearance fa.BorderSize = 0 End Sub
The code removes the border from the Button flat control except MouseOver, where I add a border of 1 pixel. In MouseLeave, I delete the border. This should show some visual feedback. This works great when the button has no focus. However, if I press the button by pressing the focus button, the mouse again and again shows that there are more than 1 pixel border around the button. I imagine that it combines a clear, clear border with 1 pixel with the traditional "Winform Button", so add a border border around the button.
How to disable / remove the "Winform Button", so add border border? Or, if I just check in ButtonMouseOver to check if the control has focus, being a condition for adding a border and just needs to be done with it? I would prefer to remove the automatic border from focus for any reason :)
source share