|
|
 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

February 17th, 2008, 08:17 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Passing variables from 1 form to another.
hi Friends,
I want to know how to pass variables from one form to another.
Thank You in advance.
Any help is welcomed
JAININ
__________________
JAININ
|

February 17th, 2008, 06:15 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
|
|
The best way is to define a public property on one form:
public string TheProperty
{
get { return _myProperty; }
}
Then you can call it from the other form, provided you have a reference to the other form:
MyForm form = (MyForm)formReference;
Console.WriteLine(form.TheProperty);
If this doesn't help then you'll have to be more specific in your requirements.
/- Sam Judson : Wrox Technical Editor -/
|

February 18th, 2008, 04:32 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think I got it. Thank u for your help.
JAININ
|

February 18th, 2008, 07:45 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I m not getting it,
Can you help me?
Actually i have an Mdi form and from it different form opens,
So i want that only 1 instance of any form is open at a given time.For that I m using a boolean variable in Mdi form. Now i want to access that boolean variable in another form which is a child form of Mdi form.
Can you solve my problem?
Thank You
JAININ
|

February 18th, 2008, 08:00 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
|
|
Inside your MdiParent you will have a property, something like this:
public bool IsFormOpen
{
get { return isFormOpenVariable; }
}
In your child you will do the following:
MyMdiParent parent = (MyMdiParent)this.MdiParent;
if( !parent.IsFormOpen )
{
// whatever
}
/- Sam Judson : Wrox Technical Editor -/
|

February 18th, 2008, 08:29 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I m still not getting it,
I want to change the value of the boolean variable in the childform and return that changed value to the MdiParent form when the child form closes,
but i get the following error.
Error 1 Property or indexer 'WindowsApplication1.MDIopeningpage.frmload' cannot be assigned to -- it is read only
Thank You.
JAININ
|

February 18th, 2008, 08:38 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
|
|
Right, you didn't say you wanted to 'change' the value, just 'access' it, so what I wrote above is a read only property.
public bool MyProperty
{
get
{
return true;
}
set
{
// do something with 'value' here.
Console.WriteLine(value);
}
}
/- Sam Judson : Wrox Technical Editor -/
|

February 18th, 2008, 09:02 AM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I m still not getting it.
I want to change the value of the boolean variable of the Mdi form on the child form and return the changed value of the boolean variable back to the Mdi form.
Thank You for helping me
|

February 18th, 2008, 09:39 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 1,340
Thanks: 0
Thanked 26 Times in 26 Posts
|
|
I'm not sure what you are having trouble with. My previous example above shows you how to write a property setter, so you can write the the property - you then store the 'value' in whatever internal variable you want to.
/- Sam Judson : Wrox Technical Editor -/
|

February 18th, 2008, 06:38 PM
|
|
Authorized User
|
|
Join Date: Feb 2008
Location: Vadodara, Gjarat, India.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The trouble is:: I have a MDI parent form and a child form for Suppplier details. Ok. Now when i first open the supplier form it opens normally and when I try yo open it again at that time it says that the form is already open.
For this i have used a boolean variable whose value is get to true once the form is opened. and that boolean variable is declared in Mdi Parent form. So now i want that when i close the Supplier form the boolean variable value should again be false.
But when I close the supplier form and try to open it again at that time also I get the message that your form is already opened. i.e.the value of the boolean variable is true only.
I want to get rid of this problem
Thank you in advance.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Passing Variables |
CMOS |
Classic ASP Basics |
2 |
January 22nd, 2006 07:38 PM |
| Passing variables |
karlirvin |
Beginning PHP |
3 |
December 9th, 2005 04:37 PM |
| passing variables. |
ashokparchuri |
ASP.NET 1.1 |
4 |
March 18th, 2005 05:36 AM |
| Passing variables |
acko |
ASP.NET 1.x and 2.0 Application Design |
1 |
December 23rd, 2003 09:40 AM |
| Passing variables |
jesseleon |
Access VBA |
4 |
October 24th, 2003 02:45 PM |
|
 |