一个ActiveX 的工程里有一个模块Mod1,一个窗体Form1,一个用户控件UserContrl
,用户控件UserContrl 里有个文本框Text1
我要在Form1 中写字到用户控件UserContrl 中怎么写?
如果不是用户控件UserContrl 中到好办,可直接引,比如在Form2中可用
Form1.text1.text="xyz"可是要引用控件里的对象不知怎么引用,请高手帮我

解决方案 »

  1.   

    学习中  我对ActiveX 很感兴趣 呵呵
      

  2.   

    选中控件,然后在新建控件里选 “VB ActiveX 控件界面向导”,然后按照提示,把控件的一个属性和控件中的TextBox的Text属性连接起来
      

  3.   

    用一个变量获取文本框的句柄,然后在窗体内把值付给ActiveX中的文本
    模块:
    Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    窗体:
    Call SetWindowText(hwnd1, "ok")
      

  4.   

    將text1.text屬性做成usercontrol的一個屬性.然後就可以在form1中給它賦值了.
      

  5.   

    定义一个属性过程,
    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="你要给的内容"
      

  6.   

    '在控件中,加入如下代码
    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
      

  7.   

    既然是用户控件,那么自定义控件中控件的就已经被封装了.无法直接访问.
    你可以设置一个属性来获得该控件text对象,
    Public Property Get frmText() As object
        set frmText = Text1
    End Property
    就可以了,不过这种方法可不好,失去了自定义控件本身的意义,只有了解什么时候需要active 控件才能更好的利用自定义控件.