C#-> form.textbox.text = label.text

M

Mohamoss

Hi Hareth
This issue is very simple. You just assign the text property of the control
you are to set ( textbox in your case ) to the text property of the other
control ( label) and use the full qualified name of the control
So if you have form named Form1 that has the label named L1 ( that has the
text you want to get ) and a button named B1 then

Form1.B1.text = Form1.L1.text;

If they are in two forms ( two differnct classes ) then one of them is
calling the other ( ie one id defined inside the other ) then you can do
the same thing with full name inside the form that has both of them
Lets say that form2 now has the button and it was created inside form1
Then you can say
Form2.B1.text = Form1.L1.text;
( but this can only be done inside Form1)
hope this helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
M

Morten Wennevik

Well, I don't know what the original message was (can't find it), but you
can simplify the sample by making textBox1 public instead of using a
property and accessing the TextBox directly. You really should use a
property instead though. In any case, you need a few lines to access
controls in another form.

In Form1.cs:
private Form2 otherForm;

public Form1(Form2 f)
{
otherForm = f;
}

void DoStuff()
{
otherForm.textBox1.Text = "Hello World";
}

In Form2.cs

public TextBox textBox1;
{
...
Form1 f = new Form1(this);
...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top