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

Windows Forms - Pass through the ShowDialog() method

I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.

Jul 25 '06 #1
11 4168
Raj
add frm.Show() method before the loaddata()

Raj

"osmarjunior" wrote:
I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.

Jul 25 '06 #2

OK. But i need the form be Modal.

I put a comment on the LoadData method line, and I tried the Show()
method. The form appears ok. If I change Show() by ShowDialog(), the
form is closing... I put a MessageBox on FormClosed event to verify
that...

Something is closing the form, but I don't have anything on Load() or
Shown() event of that form...
Raj wrote:
add frm.Show() method before the loaddata()

Raj

"osmarjunior" wrote:
I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.
Jul 25 '06 #3
Junior,
Can you post a short but complete program that demonstrates the problem:
http://www.yoda.arachsys.com/csharp/complete.html

Specifically the code in Form1 that is preventing it from being shown.

FWIW: I use Form.ShowDialog all the time & have never seen it not display a
dialog.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"osmarjunior" <os*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
|I have a sequence of commands like this:
|
| Form1 frm = new Form1();
| frm.LoadData();
|
| Boolean confirm = (frm.ShowDialog() == DialogResult.OK);
|
| The LoadData method loads information from database. The problem is,
| when I was debugging the application, it doesn't show the form. It just
| pass through the ShowDialog() method, and my flag confirm becomes
| false, because the form does not appear. What can be happening?
|
| Regards.
|
| Junior.
|
Jul 25 '06 #4
Hi,

This will solve nothing, Show is akin ShowDialog and the OP clearly stated
that he needs the form to be modal (as well as know the result of its
showing)
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Raj" <Ra*@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
add frm.Show() method before the loaddata()

Raj

"osmarjunior" wrote:
>I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.


Jul 25 '06 #5
Hi,
"osmarjunior" <os*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);
Even as there is nothing wrong with the above code I would suggest you to
move the LoadData call to inside the constructor.

Otherwise the code should work as expected, What you do in LoadData ? Where
are you filling your controls with teh data?
Are you using Form_Load event ?

Put breakpoints in both Load & Closing events of Form1
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.

Jul 25 '06 #6
Is there anything that may be setting a DialogResult in Form1?

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,
"osmarjunior" <os*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

Even as there is nothing wrong with the above code I would suggest you to
move the LoadData call to inside the constructor.

Otherwise the code should work as expected, What you do in LoadData ? Where
are you filling your controls with teh data?
Are you using Form_Load event ?

Put breakpoints in both Load & Closing events of Form1
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.
Jul 25 '06 #7
Hi,

It does not matter, there will always be a result

From MSDN:
When a form is displayed as a modal dialog box, clicking the Close button
(the button with an X at the upper-right corner of the form) causes the form
to be hidden and the DialogResult property to be set to DialogResult.Cancel.
Unlike modeless forms, the Close method is not called by the .NET Framework
when the user clicks the close form button of a dialog box or sets the value
of the DialogResult property. Instead the form is hidden and can be shown
again without creating a new instance of the dialog box. Because a form
displayed as a dialog box is not closed, you must call the Dispose method of
the form when the form is no longer needed by your application.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<sh**********@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Is there anything that may be setting a DialogResult in Form1?

Ignacio Machin ( .NET/ C# MVP ) wrote:
>Hi,
"osmarjunior" <os*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegr oups.com...
>I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

Even as there is nothing wrong with the above code I would suggest you to
move the LoadData call to inside the constructor.

Otherwise the code should work as expected, What you do in LoadData ?
Where
are you filling your controls with teh data?
Are you using Form_Load event ?

Put breakpoints in both Load & Closing events of Form1
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.

Jul 25 '06 #8

OK. I read the posts and thanks for the help. I didn't found any
solution 100% stable yet. The code I can't post here, because it's a
form with about 15 TextBoxes and other controls. It's too much code to
post here.

I just wanna make one question to you, guys: how do you free your
winforms from the memory? I always create a static method into the form
class to execute, like this:

public static Customer Execute()
{
FormCustomer frm = new FormCustomer();

if (frm.ShowDialog() == DialogResult.OK)
return frm.Customer; // returns the customer object for further
use
else
return null; // returns null, means the user
cancel the window
}

And when should I dispose the form, in the close event?

Jul 25 '06 #9
Hi,

The form will be marked to be disposed as soon as the method ends.
It will be disposed the next time the GC runs.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"osmarjunior" <os*********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>
OK. I read the posts and thanks for the help. I didn't found any
solution 100% stable yet. The code I can't post here, because it's a
form with about 15 TextBoxes and other controls. It's too much code to
post here.

I just wanna make one question to you, guys: how do you free your
winforms from the memory? I always create a static method into the form
class to execute, like this:

public static Customer Execute()
{
FormCustomer frm = new FormCustomer();

if (frm.ShowDialog() == DialogResult.OK)
return frm.Customer; // returns the customer object for further
use
else
return null; // returns null, means the user
cancel the window
}

And when should I dispose the form, in the close event?

Jul 25 '06 #10
osmarjunior,
Normally I simply wrap the entire method in a using statement:

public static Customer Execute()
{
using (FormCustomer frm = new FormCustomer())
{

if (frm.ShowDialog() == DialogResult.OK)
return frm.Customer; // returns the customer object
for further use
else
return null; // returns null, means
the user cancel the window
}
}

This ensures that the dispose method will be called when you are done with
it. It also allows the Execute method to (indirectly) access controls with
the CustomerForm.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"osmarjunior" <os*********@gmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
|
| OK. I read the posts and thanks for the help. I didn't found any
| solution 100% stable yet. The code I can't post here, because it's a
| form with about 15 TextBoxes and other controls. It's too much code to
| post here.
|
| I just wanna make one question to you, guys: how do you free your
| winforms from the memory? I always create a static method into the form
| class to execute, like this:
|
| public static Customer Execute()
| {
| FormCustomer frm = new FormCustomer();
|
| if (frm.ShowDialog() == DialogResult.OK)
| return frm.Customer; // returns the customer object for further
| use
| else
| return null; // returns null, means the user
| cancel the window
| }
|
| And when should I dispose the form, in the close event?
|
Jul 25 '06 #11

osmarjunior wrote:
I have a sequence of commands like this:

Form1 frm = new Form1();
frm.LoadData();

Boolean confirm = (frm.ShowDialog() == DialogResult.OK);

The LoadData method loads information from database. The problem is,
when I was debugging the application, it doesn't show the form. It just
pass through the ShowDialog() method, and my flag confirm becomes
false, because the form does not appear. What can be happening?

Regards.

Junior.
Hi,

Using the code:

"
Boolean confirm = (frm.ShowDIalog() == DialogResult.OK);
"

Seems to work fine in C# 2005. Haven't tried it in 2003 yet.

Is your form capable of being shown at all? Or does it work if you
don't use LoadData(), and stops working if you do use that?

Cheers,
Vincent.

Jul 26 '06 #12

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

Similar topics

0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
2
by: Chris | last post by:
I have two forms. From form one I have a listbox that when double clicked I get the selected value (string) and store in a variable. I parse the string to get the first 12 characters and store it...
4
by: Jason Huang | last post by:
Hi, Thanks for help in advance! In Form1, I "New" a Form2 and ShowDialog the Form2, it's OK. My intention is passing a value from Form2 to Form1. However, in Form2, I shouldn't "New" a Form1,...
7
by: MounilK | last post by:
Hi all, I am not sure if this is the right NG to post this question. If that's the case please point me to the correct NG. I have a class library(myLib.dll) which has a class(myClass) which has...
4
by: Mika M | last post by:
Hi! If Windows Form -application has for example a button on Form1 which Click-event opens other Form2-form like... Dim f as New Form2 f.ShowDialog() If (f.DialogResult = DialogResult.OK)...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
1
by: Michael Howes | last post by:
I and trying to detect idle time or sorts in the applications I'm building. To do this the main Form also inherits from IMessageFilter and I listen for WM_MOUSEMOVE. When that happens I reset a...
3
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The...
2
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I want to have 3 forms open modally. They are 1: a background form (bgform); 2: form_x; 3: loginform. bgform is always open. form_x could be any random form that that bgform has shown modally....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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.