Ziad Ahmed Ziad Ahmed - 3 months ago 56
Vb.net Question

borderless button in visual basic.net?

HEY there I was asking about how to make a borderless button in vb.net I can always set the style to flat and make the background color as transparent but always I always get the button focused and shows in a shape of a button which ruins my button style that I want it
here is a class I used earlier but it didn't work

Public Class ButtonEx
Inherits Button

Private _ShouldShowFocus As Boolean = False
Public Property ShouldShowFocus() As Boolean
Get
Return _ShouldShowFocus
End Get
Set(ByVal value As Boolean)
_ShouldShowFocus = value
End Set
End Property

Protected Overrides ReadOnly Property ShowFocusCues() As Boolean
Get
Return _ShouldShowFocus
End Get
End Property

End Class

Answer

You could subclass the standard button and override the OnPaint method to achieve a borderless button.

Class BorderlessButton
Inherits Button

Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
    MyBase.OnPaint(pe)
    pe.Graphics.DrawRectangle(New Pen(BackColor, 5), ClientRectangle)
End Sub

End Class

I'm assuming you've tried out the Button.FlatAppearance properties and none of these help to solve your problem.