Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > How could i use the usercontrol to call the Window Form's Componet.
 

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.

duck123  Monday, September 05, 2005 2:54 AM
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
Mohammed Elnahrawi  Tuesday, September 13, 2005 1:16 AM
 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!!"


 



RemcoJVG  Tuesday, September 06, 2005 10:44 AM
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
Mohammed Elnahrawi  Tuesday, September 13, 2005 1:16 AM

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.

duck123  Tuesday, September 13, 2005 5:42 AM

You can use google to search for other answers

Custom Search

More Threads

• Problem with the configurationManager Class
• Another Source Installation Issue
• Does XPander control needs the Manifest?
• Another stupid question "species name exists in universe"
• Updating Data Bindings
• Movement in Terrarium
• Display of ready charts from an excel file in Windows Form
• TaskVision XPanderControl: Convert IComparer implementation from VB.NET to C#
• Server source code
• ParamArray