我正在制作自定义按钮控件,并且在Text属性中遇到了一些困难。只有在窗体设计器窗口打开时,我所输入的内容才会保留。当我关闭表单设计器并重新打开它时,我的Text属性重置为“”。另外如果我运行该程序,它会丢失在设计时输入的值。自定义控件中的文本属性丢失值
我也有我的控制的图像属性工作得很好。
下面是我的一些代码:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class BlackButton
Private iText As String
Private iImage As Image
''' <summary>
''' Gets/Sets the text displayed in the button.
''' </summary>
<Browsable(True), Description("Gets or sets the text displayed on the button")> _
Public Shadows Property Text() As String
Get
Return iText
End Get
Set(ByVal value As String)
iText = value
ReDrawMe()
End Set
End Property
''' <summary>
''' Gets/Sets the image to be displayed on the button
''' </summary>
<Browsable(True), Description("Gets or sets the image displayed on the button")> _
Public Shadows Property Image() As Image
Get
Return iImage
End Get
Set(ByVal value As Image)
iImage = value
ReDrawMe()
End Set
End Property
我认真过我的代码,梳理并确保我没有任何地方将其复位。
在此先感谢您的帮助。
为什么数据停留在窗体关闭后放? – soandos 2011-05-25 22:11:45
这是一个按钮控件。在设计时为按钮输入标题时,在运行程序或关闭时应该仍然存在,然后重新打开表单设计器。我的控制不是这样做的。 – 2011-05-26 13:41:27