473,403 Members | 2,071 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,403 software developers and data experts.

Using Properties To pass fields between Dialogs

A lot of people say to use properties to pass variables between a main
dialog and a subdialog like so:

Form form = new Form();
if (form.ShowDialog()==DialogResult.OK)
{
string str = form.StrinValue;
}

but how should I close the dialog since if I do the following in the
sub form when the user presses OK, then I am destroying the instance
and so the property will not be set correctly or will not exist. How
should I 'close' the form??

private void buttonOK_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}

Also is there any difference between Show and showDialog in the way
that I should close them?

Thanks for any help.
Nick
Nov 16 '05 #1
2 3172
Nick,
I allow Windows Forms to close the dialog, instead of coding DialogResult &
Close in the buttonOK.Click event handler.

I set the buttonOk.DialogResult property to DialogResult.OK, I then set the
Form.AcceptButton property to buttonOk. Like wise for buttonCancel, I set
buttonCancel.DialogResult to DialogResult.Cancel and Form.CancelButton to
buttonCancel.

Windows Forms will then take care of closing the form and returning the
appropriate result. No need for the buttonOk.Click event handler per se.
Also is there any difference between Show and showDialog in the way
that I should close them? When you use Form.ShowDialog to display a dialog box, the form does not call
Dispose when you call Form.Close, so as to allow you to get the values of
your properties, if you use Form.Dispose you should call Form.Dispose when
you are done. I would use the using statement. When you use Form.Show,
Form.Close does call Form.Dispose.

Hope this helps
Jay

"Nick" <ni*********@hotmail.com> wrote in message
news:a0**************************@posting.google.c om... A lot of people say to use properties to pass variables between a main
dialog and a subdialog like so:

Form form = new Form();
if (form.ShowDialog()==DialogResult.OK)
{
string str = form.StrinValue;
}

but how should I close the dialog since if I do the following in the
sub form when the user presses OK, then I am destroying the instance
and so the property will not be set correctly or will not exist. How
should I 'close' the form??

private void buttonOK_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}

Also is there any difference between Show and showDialog in the way
that I should close them?

Thanks for any help.
Nick

Nov 16 '05 #2
Hi Nick,

That the form is closed (nor yet opened) does not mean it will be
destroyed, you can access its properties as with any other object you use.


private void buttonOK_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
This is fine AFAIK.
Also is there any difference between Show and showDialog in the way
that I should close them?


No really.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 16 '05 #3

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

Similar topics

16
by: Terry | last post by:
Hello, I am designing a form and need to know how to get a Check Box(PASS)to automatically update when the data in a Text Box (MARK), in the same form, is >=24. Using the Event dialogue box for...
15
by: Gary Morris | last post by:
Hello all, OK, first of all I have known about properties since VB6, which I have and have used extensively. It seems that property get and set are basically the same concept in C# and VB.NET,...
23
by: Marcin Grzębski | last post by:
I red MSDN article of C# 2.0 this week... and i found very strange syntax for properties e.g.: public int MyIntValue { get { // ... } protected set { // ... }
26
by: julien | last post by:
Hello, I don't know when to use fields and when to used properties. It looks to me that using properties is always better. But I guess fields must be better in some cases, otherwise they wouldn't...
2
by: Robert W. | last post by:
I'm trying to write a utility that will use Reflection to examine any data model I pass it and correctly map out this model into a tree structure. When I say "any" , in fact there will only be 3...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
7
by: Greg | last post by:
I am trying to convert an older console application written in C to a visual application using several Borland VCL components (open and save dialogs). I am declaring input and output stream...
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.