This is the code for my inherited Button control:
Public Class ButtonRefreshSmall
Inherits Button
Public Sub New()
MyBase.New
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.SuspendLayout()
Me.Text = ""
MyBase.Text = ""
Me.ResumeLayout()
End Sub
End Class
However, when I rebuild and drag this button to a form the text is always ButtonRefreshSmall1
. I've tried variants without the Inherits
declaration (since it's already in the .Designer.vb
file, I've tried setting Text
in Designer view/class of the control, to no avail.
Sometimes it won't even show in the Toolbox after rebuild.
All I want is for text of the button to be empty (since it has an Image
defined in the designer).
This is what I have in the Designer file:
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'ButtonRefreshSmall
'
Me.BackColor = System.Drawing.Color.Transparent
Me.FlatAppearance.BorderSize = 0
Me.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Image = Global.TraxCashFlow.My.Resources.Resources.Refresh_grey_16x
Me.Size = New System.Drawing.Size(23, 23)
Me.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText
Me.UseVisualStyleBackColor = False
'MyBase.Text = ""
Me.ResumeLayout(False)
End Sub
And all other properties are set like I set them. I tried to trick it with TextImageRelation
but the "B" is always visible anyway.
Update: Jimi gave me the idea in a comment below his answer, so I added a new Property
MyText
and this works just like I want (not sure why I need to call Refresh
though, if I don't then it's updated after losing focus):
Imports System.ComponentModel
Public Class ButtonRefreshSmall
Public Property MyText As String
Get
Return Me.Text
End Get
Set(value As String)
Me.Text = value
Me.Refresh()
End Set
End Property
Public Sub New()
'MyBase.New
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
'Me.Text = ""
End Sub
<Browsable(False)>
<DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Overrides Property Text As String
End Class
Update #2, see @TnTinMn's answer.