这是我继承的按钮控件代码:
然而,当我重新生成并将此按钮拖到表单时,文本始终为“ButtonRefreshSmall1”。我尝试了没有“Inherits”声明的变体(因为它已经在“.Designer.vb”文件中),我尝试在控件的设计器视图/类中设置“Text”,但均无效。有时,在重新生成后甚至不会显示在工具箱中。
我想要的只是将按钮的文本留空(因为在设计器中定义了一个“Image”)。这是我在设计器文件中拥有的内容:
更新 #2,请参考 @TnTinMn 的答案。
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
然而,当我重新生成并将此按钮拖到表单时,文本始终为“ButtonRefreshSmall1”。我尝试了没有“Inherits”声明的变体(因为它已经在“.Designer.vb”文件中),我尝试在控件的设计器视图/类中设置“Text”,但均无效。有时,在重新生成后甚至不会显示在工具箱中。
我想要的只是将按钮的文本留空(因为在设计器中定义了一个“Image”)。这是我在设计器文件中拥有的内容:
<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
其他所有属性都像我设置的那样设置。我尝试使用TextImageRelation
来欺骗它,但“B”总是可见的。
更新:Jimi在他的答案下面的评论中给了我这个想法,所以我添加了一个新的Property
MyText
,这正好符合我的要求(不确定为什么需要调用Refresh
,如果我不这样做的话,在失去焦点后就会更新):
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
更新 #2,请参考 @TnTinMn 的答案。