I have a main form, then this form spawns another form (Form A) as a form.showdialog(). That dialog box then has a button that spawns another form (Form B) through the form.showdialog(). All of this works fine.
Now when I press a button on Form B, and set the "this.DialogResult = DialogResult.Cancel", then close, it goes back to FormA, and Form B closes. Then Form A closes and returns to the main form. This is not what I am wanting.
I want Form A to stay open. It seems like the DialogResult is being sent back through all the forms... How can I prevent this?
6 32694
I have a main form, then this form spawns another form (Form A) as a form.showdialog(). That dialog box then has a button that spawns another form (Form B) through the form.showdialog(). All of this works fine.
Now when I press a button on Form B, and set the "this.DialogResult = DialogResult.Cancel", then close, it goes back to FormA, and Form B closes. Then Form A closes and returns to the main form. This is not what I am wanting.
I want Form A to stay open. It seems like the DialogResult is being sent back through all the forms... How can I prevent this?
Perhaps you are using Dialog boxes where you ought to be using normal forms ...
I tried what you tried and I'm not having your issue.
what I did
Form1 with button to open Form2
Form2 with button to open Form3
Form3 with button to set diaglogresult to Cancel
If fire my app, Form1 opens, I press the button, Form2 opens, I press the button Form3 opens, I press the button Form3 closes. Form2 remains open.
Form1: - private void button1_Click(object sender, EventArgs e)
-
{
-
(new Form2()).ShowDialog();
-
}
Form2: - private void button1_Click(object sender, EventArgs e)
-
{
-
(new Form3()).ShowDialog();
-
}
Form3: - private void button1_Click(object sender, EventArgs e)
-
{
-
this.DialogResult = DialogResult.Cancel;
-
}
You must 've done someting wrong. Do you set a dialogResult on the second form?
Regards
No dialog result on the second form.
I have this button click handler on the Main Form: -
private void TSB_AddBrain_Click(object sender, EventArgs e)
-
{
-
if ((new BrainForm()).ShowDialog(this) == DialogResult.OK)
-
{
-
//Add it to the main list
-
-
}
-
}
-
and then on "BrainForm" -
private void BTN_SEARCHBRAIN_Click(object sender, EventArgs e)
-
{
-
(new AutoSearchBrains()).ShowDialog();
-
}
-
and then on AutoSearchBrain Form (OK and Canel Buttons) -
#region Cancel Button Clicked
-
private void BTN_CANCEL_Click(object sender, EventArgs e)
-
{
-
this.DialogResult = DialogResult.Cancel;
-
this.Close();
-
}
-
#endregion
-
-
#region Save Button Clicked
-
private void BTN_SAVE_Click(object sender, EventArgs e)
-
{
-
this.DialogResult = DialogResult.OK;
-
if (LISTBOX_AllBrains.SelectedItem != null)
-
{
-
SendAutoBrain(FoundBrains[LISTBOX_AllBrains.SelectedIndex]);
-
}
-
else
-
{
-
ErrorForm _tempError = new ErrorForm("Select a Fusion Brain", "Please Select a Fusion Brain Instance from the list");
-
_tempError.ShowDialog();
-
return;
-
}
-
this.Close();
-
}
-
#endregion
-
It must be a setting somewhere, because if I error it and make ErrorForm appear, I can close it no problem... But again if I close AutoSearch form, BrainForm closes too regardless of the DialogResult.
What sort of setting would cause a fall through like this? Would it have to do with the button's having the same name but on different forms? All cancel buttons are named "BTN_CANCEL" and all OK buttons are "BTN_SAVE". Perhaps the event handlers are using the button name as the event trigger and not its instance or something?
Ok, solution found:
The Ok was being passed down and I dont know why. But if after the .ShowDialog() I just have to put this.DialogResult = DialogResult.None, and it will fix it. This shouldnt happen in the first place, but this fixes it, so I am not too bothered.
I had a very similar issue. I constructed a UserControl that would basically drive a whole form that you placed it into. When ever I would do a ShowDialog on it, it would appear then disappear. Really fast I might add. It was driving me up the wall until I ran across this thread. Good Job.
I had a very similar issue. I constructed a UserControl that would basically drive a whole form that you placed it into. When ever I would do a ShowDialog on it, it would appear then disappear. Really fast I might add. It was driving me up the wall until I ran across this thread. Good Job.
I did Aps that all widnows using same code. In more less half of them Described issue appears and I had to use this.DialogResult=DialogResult.None and in other half it was working OK without it.
I guess it's some serious bug in .NET
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Richard L Rosenheim |
last post by:
I would like to detect when a form is invoked as the result of a ShowDialog
call.
Anyone have any ideas or suggestions on how to do that?
TIA,
Richard Rosenheim
|
by: RubiconXing |
last post by:
Hi All
Beginner question - please be patient with me :-) I am new to c#.
If one creates a child modal (and also non-modal) form what is the
best way of returning the collected data back to the...
|
by: Nenad Dobrilovic |
last post by:
Hi,
is there any way to find out how form was closed (by calling it's method
Close() or by clicking on the 'close' button in control box)?
Also, can I close the form in that way that Cloing/Closed...
|
by: Carlos Lozano |
last post by:
Hi,
The default behavior for Modal forms does not restrict it to go out of the
client area of the main MDI container form.
I would like to show a modal form and keep it within the application...
|
by: Mike |
last post by:
Hi, I already asked such question and also got some comments but when
I added details - no more responds.
Ok, here the story:
Main form starts the additional thread.
The thread contain such...
| |
by: Wardeaux |
last post by:
All,
I have login form used with ShowDialog(). I have the AcceptButton
property set so that the "Enter" key is mapped. I also need to keep the
dialog open when the UserID and PWD are invalid so...
|
by: sylvain |
last post by:
is there a simple way to detect a web window closing when the user hit the X
of the browser ? I want to display a message to the user when he goes out of
my web page.
I try to detect it by using...
|
by: =?Utf-8?B?UGhpbA==?= |
last post by:
I have a modal form (ShowDialog()) that I may want to close when a user
clicks a button. I already have an OK and Cancel button, so I can't use
those options, but I want it to function just like...
|
by: ponvijaya |
last post by:
Hi all,
My project is done in Tomcat 5.0 with Mysql 5 as backend.
Through tomcat admin console i have configured datasource named "mine" with all the attributes needed to connect to MySql like...
|
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,...
|
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...
| |
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: 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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |