VB中用户控件的问题
我的用户控件里面放了一个Picture和一个Label,在设置控件接口的时候Label映射的是Caption属性,Picture映射的是Picture属性。用户控件代码如...
我的用户控件里面放了一个Picture和一个Label,在设置控件接口的时候Label映射的是Caption属性,Picture映射的是Picture属性。
用户控件代码如下:
Option Explicit
'注意!不要删除或修改下列被注释的行!
'MappingInfo=Label1,Label1,-1,Caption
Public Property Get Caption() As String
Caption = Label1.Caption
End Property
Public Property Let Caption(ByVal New_Caption As String)
Label1.Caption() = New_Caption
PropertyChanged "Caption"
End Property
'注意!不要删除或修改下列被注释的行!
'MappingInfo=Picture1,Picture1,-1,Picture
Public Property Get Picture() As Picture
Set Picture = Picture1.Picture
End Property
Public Property Set Picture(ByVal New_Picture As Picture)
Set Picture1.Picture = New_Picture
PropertyChanged "Picture"
End Property
'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = PropBag.ReadProperty("Caption", "Label1")
Set Picture = PropBag.ReadProperty("Picture", Nothing)
End Sub
'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Caption", Label1.Caption, "Label1")
Call PropBag.WriteProperty("Picture", Picture, Nothing)
End Sub
但是我在窗体中使用用户控件的时候,只有Caption可以用到,Picture就用不到了(可以感应到),代码如下:
Private Sub Form_Load()
UserControl11.Caption = "XXXXXXXXXXXXXXX"
UserControl11.Picture = LoadPicture(App.Path & "\a\b.jpg")
End Sub
但每次一运行就提示“属性的使用无效”
我明明已经把Picture属性映射给UserControl1中的Picture控件了,为什么会说使用无效呢?
请求帮助,万分感激 展开
用户控件代码如下:
Option Explicit
'注意!不要删除或修改下列被注释的行!
'MappingInfo=Label1,Label1,-1,Caption
Public Property Get Caption() As String
Caption = Label1.Caption
End Property
Public Property Let Caption(ByVal New_Caption As String)
Label1.Caption() = New_Caption
PropertyChanged "Caption"
End Property
'注意!不要删除或修改下列被注释的行!
'MappingInfo=Picture1,Picture1,-1,Picture
Public Property Get Picture() As Picture
Set Picture = Picture1.Picture
End Property
Public Property Set Picture(ByVal New_Picture As Picture)
Set Picture1.Picture = New_Picture
PropertyChanged "Picture"
End Property
'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = PropBag.ReadProperty("Caption", "Label1")
Set Picture = PropBag.ReadProperty("Picture", Nothing)
End Sub
'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Caption", Label1.Caption, "Label1")
Call PropBag.WriteProperty("Picture", Picture, Nothing)
End Sub
但是我在窗体中使用用户控件的时候,只有Caption可以用到,Picture就用不到了(可以感应到),代码如下:
Private Sub Form_Load()
UserControl11.Caption = "XXXXXXXXXXXXXXX"
UserControl11.Picture = LoadPicture(App.Path & "\a\b.jpg")
End Sub
但每次一运行就提示“属性的使用无效”
我明明已经把Picture属性映射给UserControl1中的Picture控件了,为什么会说使用无效呢?
请求帮助,万分感激 展开
1个回答
展开全部
lic Property Get Caption() As String
Caption = Label1.Caption
End Property
Public Property Let Caption(ByVal vNewValue As String)
Label1.Caption = vNewValue
End Property
'补充,我明白你的意思了=======================
’将下面语句再添加到你的用户控件模块中
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = PropBag.ReadProperty("Caption", "Label1")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Caption", Label1.Caption, "Label1"
End Sub
Caption = Label1.Caption
End Property
Public Property Let Caption(ByVal vNewValue As String)
Label1.Caption = vNewValue
End Property
'补充,我明白你的意思了=======================
’将下面语句再添加到你的用户控件模块中
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = PropBag.ReadProperty("Caption", "Label1")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Caption", Label1.Caption, "Label1"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询