473,652 Members | 3,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4211
Raj
add frm.Show() method before the loaddata()

Raj

"osmarjunio r" 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

"osmarjunio r" 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
"osmarjunio r" <os*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.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*@discussion s.microsoft.com wrote in message
news:98******** *************** ***********@mic rosoft.com...
add frm.Show() method before the loaddata()

Raj

"osmarjunio r" 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,
"osmarjunio r" <os*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.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,
"osmarjunio r" <os*********@gm ail.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.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.Ca ncel.
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**********@g mail.comwrote in message
news:11******** *************@h 48g2000cwc.goog legroups.com...
Is there anything that may be setting a DialogResult in Form1?

Ignacio Machin ( .NET/ C# MVP ) wrote:
>Hi,
"osmarjunior " <os*********@gm ail.comwrote in message
news:11******* **************@ b28g2000cwb.goo glegroups.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.mach in 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
"osmarjunio r" <os*********@gm ail.comwrote in message
news:11******** **************@ m79g2000cwm.goo glegroups.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

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

Similar topics

0
2308
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 example source code can be downloaded here: http://www.blogitek.com/timhaughton/archives/files/User%20Interrogator%20And%20TDD.zip The article text is below. Not sure what it will do to the formatting when
2
17972
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 in a variable to query a sql db. I set break points to see the data as it is passed from form1 and when calling the function from form2 to get the variable, its contents are blank. I believe what I'm looking for is some method to access an...
4
1984
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, 'cuz it will open a new Form1, the new Form1 will get the value. And the original Form1 get nothing! What do I need to do to let the ORIGINAL Form1 get the target value? Any help will be highly appreciated.
7
1908
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 a method(myClassMethod) that creates a form with a button on it. The application that calls the dll is a windows application(myWinApp). When in myWinApp I do, myClass.myClassMethod, a form is created.
4
1573
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) Then SaveText(f.txtInput.Text) End If
8
36118
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 button on it. If the query returns multiple results, a new window is opened with a grid containing the results. When the user double clicks on the desired row in the grid, I want the first form to populate with the correct data. I don't know how...
1
1963
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 DateTime. To check the time between last mouse move I have a timer (System.Threading.Timer) If the the DateTime math meets a certain threshold I want to show our login dialog, essentially locking people out of this unattended app.
3
4680
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 form that has the System.Windows.Forms.LinkLabel controls on it is in a different project and under a different namespace from the file where the LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog under the LinkClicked method. ...
2
241
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. Whenever, the pc is idle for x minutes then loginform is displayed. This all works fine, except that loginform does not seem to be a child of form_x. Hence I am able to interact with form_x. I want the focus to be on loginform until it is closed. here...
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.