hi,
i work on windows application and i want to know how to use the components (textboxes,..) of a winform in another winform.
thanks

Recommended Answers

All 2 Replies

Here's an example:

Form1's Constructor:

Form2 form2;

public Form1()
{
    InitializeComponent();

    form2 = new Form2(this);
}

Form2's Constructor:

Form1 form1;

public Form2(Form1 F)
{
    InitializeComponent();

   form1 = F;
}

Now set the Modifiers property of the control (on any form) to "Public":

[img]http://i.imgur.com/IzNSu.jpg[/img]

And you can then access it like this:

Accessing a Label on Form2 from Form1:

// Form1

string labelText = form2.label1.Text;

Hope that helps.

Thanks

commented: THANK YOU THANK YOU +0

Thank you so much for the code you really help me. thanks again...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.