一个ActiveX 的工程里有一个模块Mod1,一个窗体Form1,一个用户控件UserContrl
,用户控件UserContrl 里有个文本框Text1
我要在Form1 中写字到用户控件UserContrl 中怎么写?
如果不是用户控件UserContrl 中到好办,可直接引,比如在Form2中可用
Form1.text1.text="xyz"可是要引用控件里的对象不知怎么引用,请高手帮我
,用户控件UserContrl 里有个文本框Text1
我要在Form1 中写字到用户控件UserContrl 中怎么写?
如果不是用户控件UserContrl 中到好办,可直接引,比如在Form2中可用
Form1.text1.text="xyz"可是要引用控件里的对象不知怎么引用,请高手帮我
模块:
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
窗体:
Call SetWindowText(hwnd1, "ok")
eg:'//at your usercontrol
'at global declarations
'define a variable to store the text1 contents
public property Get txtString()as string
'//add code here
end property
public property Let txtString(byval str as string)
'//add code here
end property
'//at you form
youUserControlName.txtstring="你要给的内容"
Public Property Get Text() As String
Text = Text1.Text
End PropertyPublic Property Let Text(ByVal New_Text As String)
Text1.Text() = New_Text
PropertyChanged "Text"
End Property'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Text1.Text = PropBag.ReadProperty("Text", "Text1")
End Sub'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag) Call PropBag.WriteProperty("Text", Text1.Text, "Text1")
End Sub
你可以设置一个属性来获得该控件text对象,
Public Property Get frmText() As object
set frmText = Text1
End Property
就可以了,不过这种方法可不好,失去了自定义控件本身的意义,只有了解什么时候需要active 控件才能更好的利用自定义控件.