473,382 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 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 10485
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: BillZondlo | last post by:
How come when I put the label text setting here: /// The main entry point for the application. /// </summary> static void Main() { Application.Run(new Form1()); } private void LoadInfo()
2
by: Al the programmer | last post by:
I have an asp.net page with textbox and label controls. The controls have a text property. When I change the text property how do I get it to render on the user's browser?
2
by: mark | last post by:
i have a freetype text box which contains text like (not exactly like this!!) :- { textext eteasdadadasdasddddddddddddddaasdasd wqeqeqweqweqwe qweqeqeqeqwewqerqerqwerqwerqwerqwerqwerqw...
16
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
6
by: Roger Ries via DotNetMonster.com | last post by:
I'm trying to change the text in a label from another form. lblInfo.Text = "ABC" Works for the form your currently in but how the heck do you change that label information from another form. ...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.