Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Hareth
Guest
 
Posts: n/a
#1: Nov 16 '05
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)..


Mohamoss
Guest
 
Posts: n/a
#2: Nov 16 '05

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


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

Morten Wennevik
Guest
 
Posts: n/a
#3: Nov 16 '05

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


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 <abiheiri@hotmail.com> wrote:
[color=blue]
> 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)..
>
>[/color]



--
Happy Coding!
Morten Wennevik [C# MVP]
Closed Thread