【发布时间】:2011-05-25 22:08:17
【问题描述】:
我正在制作自定义按钮控件,但我的 Text 属性遇到了一些困难。我输入的任何内容都只会在表单设计器窗口打开时保留。当我关闭表单设计器并重新打开它时,我的 Text 属性重置为“”。此外,如果我运行该程序,它会丢失在设计时输入的值。
我的控件还有一个 Image 属性,它工作得很好。
这是我的一些代码:
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
我仔细梳理了我的代码,并确保我没有在任何地方重置它。
在此先感谢您提供任何帮助。
【问题讨论】:
-
为什么表格关闭后数据仍然保留?
-
这是一个按钮控件。当您在设计时为按钮输入标题时,当您运行程序或关闭然后重新打开表单设计器时,它应该仍然存在。我的控件没有这样做。
标签: vb.net controls properties