How could i use the usercontrol to call the Window Form's Componet.

I create a user controls and added it on a Form.
There are also an textBox on the same Form.

But i can't assign an text string to the textBox on the Form by codding  in the user control .

How could i do it.




Answer this question

How could i use the usercontrol to call the Window Form's Componet.

  • Chrisfquinn

     duck123 wrote:

    I create a user controls and added it on a Form.
    There are also an textBox on the same Form.

    But i can't assign an text string to the textBox on the Form by codding  in the user control .

    How could i do it.



    i don't know why you want to do that, but i could be done something like this:



    ' member variable in usercontrol

    Private _HostedTextbox As TextBox

    'property on the usercontrol

    Public Property HostedTextBox() As TextBox

    Get

    Return Me._HostedTextbox

    End Get

    Set(ByVal value As TextBox)

    Me._HostedTextbox = value

    End Set

    End Property

     

     


    Then in the form designer-propertygrid you see in the usecontrol a property usercontrol
    Set this property to the textbox you like, this could be any textbox on the form


    in your usercontrol you could say now something like this



    me.Hostedcontrol.text = "Tada!!"


     




  • egady1

    As we know , very window form application has some buttons collection, like "Previous","next","first","last" and so on...

    I want to make a usercontrol to re-usedable on very window Form .

    I thouht that would be the best way to create  application.



  • kalaria

    Ther is many ways to do that , here i assumes that you will set a Button on your User Control , And you have a Textbox control on your main form


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim obj As New Object
    obj = Me.FindForm
    MessageBox.Show(obj.controls("TextBox1").text)

    End Sub

     


    Thats all

  • How could i use the usercontrol to call the Window Form's Componet.