473,473 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why when I open this form using ShowDialog() it becomes modal..

I am using the no-arg ShowDialog() method hoping that the window would not be
modal to any other window like the other ShowDialog(IWin32Window) method
does, but when this opens it somehow becomes modal to my main window- even
though I don't see how it could even be getting a reference to my main window.

What I need is to open a new window but still have my main window available
for interaction- the way it opens now it forces focus on this new window....

The last time I tried using just the Show() method it wound up just opening
the window for a split second before it vanishes away- and I wans;t doing
anything with the DialogResult variable.

nothing fancy here... just goes something like this:

on request:
MyDialog dialog = new MyDialog();
dialog.ShowDialog();

(dialog opens but becomes modal to the window that opened it, despite not
passing in a reference to itself)

Any ideas would be greatly appreciated
Nov 16 '05 #1
5 3849
Ok well, using Show() will do what I want for one Form, but the other Form
just flickers on screen then goes away. I tried looking for what difference
causing this problem but can't find any reason... they are not complicated
dialogs at all, one has a Menu and a DataGrid, the other has a TreeView and a
Label. The one with the TreeView is the one that just won't stay open unless
I use ShowDialog, but then of course it becomes modal which is bad...

In both cases I have an global instance variable so there's no question
about the reference to the dialog going out of scope. These objects holding
reference to the dialogs are 100% active before and after these dialogs are
shown.

I am not playing aroud with DialogResult in either of the forms, there is no
Load event or anything bizarre going on in the initialization.... I'm really
stumped here
Nov 16 '05 #2

Sorry, one more update... I added a new windows form to my project, made
absolutely no changes to it so it's just a blank windows form and tried the
same thing on that. It too just flashes on screen.

My main window opens it, and it loks like this:

MyDialog dialog; // class variable

public void ShowMyDialog () {
dialog = new MyDialog();
dialog.Show();
}

simple as that... so is there somethign I am totally misunderstanding about
the way windows Forms work? I am not experienced with GUI development (which
should be clear by now!)

The kicker is that my form holding a DataGrid uses the same idea, and it
displays and stays on screen no problem...

Nov 16 '05 #3
OK I do believe the mystery is finally solved, but I'm still kind of confused.

I was looking in the wrong places- I was thinking there was something wrong
with the Forms- there isn't, there's indeed a very subtle difference in the
way the windows were instantiated.

The situation is this, I have several worker threads when my app initializes
and they all report to one 'manager'. When the manager (who is another new
thread himsself) gets word that all his workers are done, he reports to my
main window so a status can be updated and several controls enabled. This is
done through an event. When this event is triggered it calls a method on my
main app which in turn opens that dialog that flashes on screen and
disappears. So now what I'm thinking is for whatever reason- that dialog
became associated with that manager's thread, so when that thread got
disposed of it took that dialog with it.

What I don't understand is why... why would that dialog belong to the
manager thread if I passed a delegate on behalf of my main window to open
that dialog?

It looks something like this:

// constructor for my main window
public MainWindow {

// standard form init code ...

Manager mgr = new Manager();
mgr.Load += new LoadCompelteDelegate(LoadComplete);
mgr.Start(); // manager spawns workers and begins work
}

// my delegate
public void LoadComplete () {
// other code...

MyDialog dialog = new MyDialog();
dialog.Show();
}

I guess one solution which I don't like is to get rid of Manager and put
that code in my main window, so I can be sure the thread opening the dialog
won't go away.

The other is some solution I found on the web for a slightly different
problem, but may be what I need. I would create another method whose sole
purpose is to open MyDialog. Then in LoadComplete, I would make a delegate
for this method and then call my main window's Invoke method to invoke that
method through it's thread.

I tried it out and it seems to work, but can you make sure I did it right?

// inside of LoadComplete :
OpenDialogDelegate openDialog = new OpenDialogDelegate(OpenDialog);
this.Invoke(openDialog, new object[] { });

anythign wrong with that?
Nov 16 '05 #4
You are creating the dialog in the LoadComplete function, as soon as the
dialog.Show returns the function competes and the dialog goes out of scope
and disappears. If you want the dialog to remain you must declare the
variable dialog at the class level so that it stays in scope when the
function ends.

"MrNobody" wrote:
OK I do believe the mystery is finally solved, but I'm still kind of confused.

I was looking in the wrong places- I was thinking there was something wrong
with the Forms- there isn't, there's indeed a very subtle difference in the
way the windows were instantiated.

The situation is this, I have several worker threads when my app initializes
and they all report to one 'manager'. When the manager (who is another new
thread himsself) gets word that all his workers are done, he reports to my
main window so a status can be updated and several controls enabled. This is
done through an event. When this event is triggered it calls a method on my
main app which in turn opens that dialog that flashes on screen and
disappears. So now what I'm thinking is for whatever reason- that dialog
became associated with that manager's thread, so when that thread got
disposed of it took that dialog with it.

What I don't understand is why... why would that dialog belong to the
manager thread if I passed a delegate on behalf of my main window to open
that dialog?

It looks something like this:

// constructor for my main window
public MainWindow {

// standard form init code ...

Manager mgr = new Manager();
mgr.Load += new LoadCompelteDelegate(LoadComplete);
mgr.Start(); // manager spawns workers and begins work
}

// my delegate
public void LoadComplete () {
// other code...

MyDialog dialog = new MyDialog();
dialog.Show();
}

I guess one solution which I don't like is to get rid of Manager and put
that code in my main window, so I can be sure the thread opening the dialog
won't go away.

The other is some solution I found on the web for a slightly different
problem, but may be what I need. I would create another method whose sole
purpose is to open MyDialog. Then in LoadComplete, I would make a delegate
for this method and then call my main window's Invoke method to invoke that
method through it's thread.

I tried it out and it seems to work, but can you make sure I did it right?

// inside of LoadComplete :
OpenDialogDelegate openDialog = new OpenDialogDelegate(OpenDialog);
this.Invoke(openDialog, new object[] { });

anythign wrong with that?

Nov 16 '05 #5
Hi tony, thanks for your reply !

I apologize- I didn;t copy the code to this message, I just rewrote parts of
it and renamed everything to something simple in an attempt not to confuse
anyone with something irrelevent, and in the process I turned the class
instance variable in my project to a local instance one in this message. So
it was indeed a class instance variable- again sorry for the confusion.

"tony lock" wrote:
You are creating the dialog in the LoadComplete function, as soon as the
dialog.Show returns the function competes and the dialog goes out of scope
and disappears. If you want the dialog to remain you must declare the
variable dialog at the class level so that it stays in scope when the
function ends.

Nov 16 '05 #6

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

Similar topics

4
by: kids_pro | last post by:
Hi there, I want to create a Modal dialog from. Normally in vb it won't allow to click the parent form. But I tried that in C# using form.ShowDialog(this); I still can click on the mainForm...
4
by: Paul Aspinall | last post by:
Can anyone advise how to display a form on top, and modal, without using ShowDialog?? Thanks
14
by: I_AM_DON_AND_YOU? | last post by:
Hello all: Yesterday I put this post regarding the query as to how to open a new form in "modal" style. I am calling the form in the following way: dim frm as form2() frm = new form2()...
7
by: Boni | last post by:
Dear all, if I do myform.close() is it disposed or not? is it correct do following? myForm.close() Info=SomeControlOntheForm.text This seems to work. But am not sure that it is waterproof....
6
by: Aziz | last post by:
Here's the problem. On my OrderForm the user can click a link to open up the AddCustomer form to add a new customer, when AddCustomer form closes, it saves the customer to the DataBase. The...
1
by: SammyBar | last post by:
Hi all, I'm having troubles with a Symbol 9000 device (Compact Framework v 1.1) when activating the barcode scanner from a window. The problem is related to the Activated event of the form which...
5
by: Michael.Suarez | last post by:
Suppose I have a button on a form that opens up another form. the code in the buttons click event is: frmMyCustomForm frm = new frmMyCustomForm (); frm.ShowDialog(); frm.Dispose(); The...
1
by: Frank Rizzo | last post by:
I am not grokking the difference between Form.ShowDialog() and Form.ShowDialog(this). I have a form (parent form) that kicks off a modal dialog using Form.ShowDialog(). The modal dialog has a 3rd...
0
by: =?Utf-8?B?a20=?= | last post by:
I've got a simple C# app built in VS2005. When I click a menu item a modal form opens and performs a lengthy operation in the Load event handler to populate a text control, so it takes a few...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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
tracyyun
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.