473,320 Members | 1,695 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,320 software developers and data experts.

Accessing properties of Controls in another Form

I have 2 forms (Form1 and Form2) in my C# project. I created the second form
from the main form like so:

Fom2 aForm = new Form2();
aForm.ShowDialog();

How do I access the properties of a control (label1) in Form1 from Form2?

Thanks
Andrew
Nov 16 '05 #1
4 4317

http://www.codeproject.com/csharp/PassDataDelegate.asp
Using a delegate to pass data between two forms

Andrew Diabo wrote:
I have 2 forms (Form1 and Form2) in my C# project. I created the second
form from the main form like so:

Fom2 aForm = new Form2();
aForm.ShowDialog();

How do I access the properties of a control (label1) in Form1 from Form2?

Thanks
Andrew


--
Texeme
http://texeme.com

Nov 16 '05 #2
hi
Check this article also
http://www.c-sharpcorner.com/Code/20...ataInForms.asp

Regards
Ansil
Trivandrum

"Andrew Diabo" wrote:
I have 2 forms (Form1 and Form2) in my C# project. I created the second form
from the main form like so:

Fom2 aForm = new Form2();
aForm.ShowDialog();

How do I access the properties of a control (label1) in Form1 from Form2?

Thanks
Andrew

Nov 16 '05 #3
RCS
I'd say you shouldn't directly manipulate controls on another form, but if
you need to - you could also do something like this:

from form2:

((Label)parent.Controls.Find("label1",true)[0]).Text = "Hello there";
"Andrew Diabo" <An*********@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
I have 2 forms (Form1 and Form2) in my C# project. I created the second
form
from the main form like so:

Fom2 aForm = new Form2();
aForm.ShowDialog();

How do I access the properties of a control (label1) in Form1 from Form2?

Thanks
Andrew

Nov 16 '05 #4
Thanks Elidel, Ansil and RCS for the very helpful tips.

Andrew
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
4
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access...
5
by: Jonathan Williams | last post by:
Hi, I have an object which inherits from WebControl (CUSTOM : WebControl) In this object I have code in which I add child contols: protected override void CreateChildControls() {...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
8
by: Mike Caputo | last post by:
In VB.NET, need to be able to access certain properties on my main form from other forms. These are properties that may be changed by the user, so I have to be able to get to them throughout the...
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
3
by: M K | last post by:
I have 2 classes. One where the form resides and I created another one for all the database stuff. after i get data from the db i want to be able to update the form. I have the namespace of...
0
by: porksmash | last post by:
I'm developing an app here that uses ActiveX controls to connect to industrial cameras over Ethernet. I want to be able to dynamically create those controls at runtime based on how many cameras are...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.