472,127 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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

i got the idea "form.textbox.text = label.text" from vb...

i tried it in C# but it generated errors
i found a diff example from :
http://msdn.microsoft.com/library/de...ormvisualc.asp

but its too confusing for me, and i think its too much work for such an easy
code...

anyone has an easier way?

preferably a one/two line code...instead of 5 lines in two diff forms
(check weblink I posted)..
Nov 16 '05 #1
2 10385
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

Nov 16 '05 #2
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);
...
}

On Sun, 24 Oct 2004 00:19:44 -0400, Hareth <ab******@hotmail.com> wrote:
i got the idea "form.textbox.text = label.text" from vb...

i tried it in C# but it generated errors
i found a diff example from :
http://msdn.microsoft.com/library/de...ormvisualc.asp

but its too confusing for me, and i think its too much work for such an
easy
code...

anyone has an easier way?

preferably a one/two line code...instead of 5 lines in two diff forms
(check weblink I posted)..


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by BillZondlo | last post: by
2 posts views Thread by Al the programmer | last post: by
2 posts views Thread by mark | last post: by
6 posts views Thread by Roger Ries via DotNetMonster.com | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.