PC Review


Reply
Thread Tools Rate Thread

Accessing properties of Controls in another Form

 
 
=?Utf-8?B?QW5kcmV3IERpYWJv?=
Guest
Posts: n/a
 
      7th Feb 2005
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
 
Reply With Quote
 
 
 
 
Elidel
Guest
Posts: n/a
 
      7th Feb 2005

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

 
Reply With Quote
 
=?Utf-8?B?QW5zaWwgTUNBRA==?=
Guest
Posts: n/a
 
      7th Feb 2005
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

 
Reply With Quote
 
RCS
Guest
Posts: n/a
 
      7th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:48DC2B9A-9865-41D4-BABA-(E-Mail Removed)...
>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



 
Reply With Quote
 
=?Utf-8?B?QW5kcmV3IERpYWJv?=
Guest
Posts: n/a
 
      7th Feb 2005
Thanks Elidel, Ansil and RCS for the very helpful tips.

Andrew
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing (!) subform controls properties at runtime AlexT Microsoft Access Forms 4 9th Nov 2005 09:55 AM
Accessing Properties of Dynamically added Web User Controls =?Utf-8?B?QnJpYW4=?= Microsoft ASP .NET 1 6th May 2005 05:13 PM
Accessing properties of multiple (different) controls jralford Microsoft C# .NET 3 7th Mar 2005 07:18 AM
Accessing methods and properties of dynamically loaded controls Jeff Smith Microsoft ASP .NET 1 11th Oct 2004 02:49 PM
User Controls and accessing public properties Paul Microsoft ASP .NET 2 9th Jan 2004 09:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:09 PM.