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

Calling form knowledge of closing modeless form


Does anyone know how to detect a modeless form on closing by the form that
invoked the modeless form?

form.Show();
Nov 16 '05 #1
6 3198
RCS
I don't believe that there is an inherent way. How I'd do this, is maybe
have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...

Does anyone know how to detect a modeless form on closing by the form that
invoked the modeless form?

form.Show();

Nov 16 '05 #2
Thanks for the input.

It seems strange to me that there is no 'event' that could be triggered by
the modeless form to signal the parent/calling form it is closing.

I assume the child modeless form is a thread off the parent. There are ways
of monitoring a thread correct?

Gary

"RCS" wrote:
I don't believe that there is an inherent way. How I'd do this, is maybe
have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...

Does anyone know how to detect a modeless form on closing by the form that
invoked the modeless form?

form.Show();


Nov 16 '05 #3
The forms will run on the same thread, unless special action
is taken to run them on separate threads (but that is unusual).

I'm not sure I understood the original question clearly, but to have
the main form detect when a modeless form closes, it could simply
subscribe to the "Closed" event of the modeless form.

In the following very simple application clicking the main form will
open a modeless form, and when the modeless form is closed the
main form will respond by changing its background to some random
color.

public class MainForm : Form
{
public MainForm()
{
Text = "Main Form";
}

protected override void OnClick(EventArgs e)
{
Form modelessForm = new Form();
modelessForm.Text = "Modeless Form";
modelessForm.Closed += new EventHandler(modelessForm_Closed);
modelessForm.Show();
}

static void Main()
{
Application.Run(new MainForm());
}

private void modelessForm_Closed(object sender, EventArgs e)
{
Random random = new Random();
BackColor = Color.FromArgb(random.Next(255),
random.Next(255), random.Next(255));
}
}

- Magnus
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
Thanks for the input.

It seems strange to me that there is no 'event' that could be triggered by
the modeless form to signal the parent/calling form it is closing.

I assume the child modeless form is a thread off the parent. There are
ways
of monitoring a thread correct?

Gary

"RCS" wrote:
I don't believe that there is an inherent way. How I'd do this, is maybe
have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to
the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of
code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
>
> Does anyone know how to detect a modeless form on closing by the form
> that
> invoked the modeless form?
>
> form.Show();


Nov 16 '05 #4
Magnus,

Yes that is exactly what I wanted. Thanks for taking the time to reply.

I looked through MS and I did read about events and delegates but I was not
convinced that was what I needed.

I also read the great 'How to' on making a modeless form act as a modal form.

I have no idea what MS thinks when it post such complexity.

Now I am confused about the necessity of a 'delegate'.

Gary

"Magnus Krisell" wrote:
The forms will run on the same thread, unless special action
is taken to run them on separate threads (but that is unusual).

I'm not sure I understood the original question clearly, but to have
the main form detect when a modeless form closes, it could simply
subscribe to the "Closed" event of the modeless form.

In the following very simple application clicking the main form will
open a modeless form, and when the modeless form is closed the
main form will respond by changing its background to some random
color.

public class MainForm : Form
{
public MainForm()
{
Text = "Main Form";
}

protected override void OnClick(EventArgs e)
{
Form modelessForm = new Form();
modelessForm.Text = "Modeless Form";
modelessForm.Closed += new EventHandler(modelessForm_Closed);
modelessForm.Show();
}

static void Main()
{
Application.Run(new MainForm());
}

private void modelessForm_Closed(object sender, EventArgs e)
{
Random random = new Random();
BackColor = Color.FromArgb(random.Next(255),
random.Next(255), random.Next(255));
}
}

- Magnus
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
Thanks for the input.

It seems strange to me that there is no 'event' that could be triggered by
the modeless form to signal the parent/calling form it is closing.

I assume the child modeless form is a thread off the parent. There are
ways
of monitoring a thread correct?

Gary

"RCS" wrote:
I don't believe that there is an inherent way. How I'd do this, is maybe
have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to
the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of
code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
>
> Does anyone know how to detect a modeless form on closing by the form
> that
> invoked the modeless form?
>
> form.Show();


Nov 16 '05 #5
Or if you wanted the new form to pass information back to the main form, you
could provide a method in the main form to react to the new form ... The
2nd form could hide itself, then call the main form's method. The main form
could take the info it needs from the 2nd form and then call Dispose() on
the 2nd form.

The following should have the same behavior as Magnus's example (but in real
life, the newForm would be
responsible for collection the information so the MainForm could use it.)

public class MainForm : Form
{
public MainForm()
{
Text = "Main Form";
}

protected override void OnClick(EventArgs e)
{
newForm modelessForm = new newForm(this);
modelessForm.Text = "Modeless Form";
modelessForm.Show();
}

static void Main()
{
Application.Run(new MainForm());
}

internal void modelessFormClosing(newForm frm)
{
BackColor = frm.Info;
}
}

public class newForm : Form
{
private Color info;
private Random random = new Random();
private MainForm theMainForm;

public newForm(MainForm frm)
{
theMainForm = frm;
info = Color.FromArgb(random.Next(255),
random.Next(255), random.Next(255));
this.Closing += new
System.ComponentModel.CancelEventHandler(this.newF orm_Closing);
}

public Color Info{ get{return info;}}

private void newForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
theMainForm.modelessFormClosing(this);
}
}

"Magnus Krisell" <ma******@NOSPAMstudent.liu.se> wrote in message
news:Of*************@TK2MSFTNGP15.phx.gbl...
The forms will run on the same thread, unless special action
is taken to run them on separate threads (but that is unusual).

I'm not sure I understood the original question clearly, but to have
the main form detect when a modeless form closes, it could simply
subscribe to the "Closed" event of the modeless form.

In the following very simple application clicking the main form will
open a modeless form, and when the modeless form is closed the
main form will respond by changing its background to some random
color.

public class MainForm : Form
{
public MainForm()
{
Text = "Main Form";
}

protected override void OnClick(EventArgs e)
{
Form modelessForm = new Form();
modelessForm.Text = "Modeless Form";
modelessForm.Closed += new EventHandler(modelessForm_Closed);
modelessForm.Show();
}

static void Main()
{
Application.Run(new MainForm());
}

private void modelessForm_Closed(object sender, EventArgs e)
{
Random random = new Random();
BackColor = Color.FromArgb(random.Next(255),
random.Next(255), random.Next(255));
}
}

- Magnus
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
Thanks for the input.

It seems strange to me that there is no 'event' that could be triggered by the modeless form to signal the parent/calling form it is closing.

I assume the child modeless form is a thread off the parent. There are
ways
of monitoring a thread correct?

Gary

"RCS" wrote:
I don't believe that there is an inherent way. How I'd do this, is maybe have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of
code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
>
> Does anyone know how to detect a modeless form on closing by the form
> that
> invoked the modeless form?
>
> form.Show();


Nov 16 '05 #6
RCS
Wow - excellent solution, that hadn't dawned on me!!!

Now that's what I call using the technology to your advantage!
"Magnus Krisell" <ma******@NOSPAMstudent.liu.se> wrote in message
news:Of*************@TK2MSFTNGP15.phx.gbl...
The forms will run on the same thread, unless special action
is taken to run them on separate threads (but that is unusual).

I'm not sure I understood the original question clearly, but to have
the main form detect when a modeless form closes, it could simply
subscribe to the "Closed" event of the modeless form.

In the following very simple application clicking the main form will
open a modeless form, and when the modeless form is closed the
main form will respond by changing its background to some random
color.

public class MainForm : Form
{
public MainForm()
{
Text = "Main Form";
}

protected override void OnClick(EventArgs e)
{
Form modelessForm = new Form();
modelessForm.Text = "Modeless Form";
modelessForm.Closed += new EventHandler(modelessForm_Closed);
modelessForm.Show();
}

static void Main()
{
Application.Run(new MainForm());
}

private void modelessForm_Closed(object sender, EventArgs e)
{
Random random = new Random();
BackColor = Color.FromArgb(random.Next(255),
random.Next(255), random.Next(255));
}
}

- Magnus
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
Thanks for the input.

It seems strange to me that there is no 'event' that could be triggered
by
the modeless form to signal the parent/calling form it is closing.

I assume the child modeless form is a thread off the parent. There are
ways
of monitoring a thread correct?

Gary

"RCS" wrote:
I don't believe that there is an inherent way. How I'd do this, is maybe
have a public static collection property (that is of type Form) on the
"main" form class, and have the child windows add thier window handle to
the
collection when it starts, and remove it when it is closing.

meanwhile, on the main form, put your appropriate get and set chunks of
code
to handle other things.. for example, on your set, maybe you say:

if ( value.Text == "My Second Window" )
// do something

hope that helps..
"Gary Miller" <Ga********@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
>
> Does anyone know how to detect a modeless form on closing by the form
> that
> invoked the modeless form?
>
> form.Show();


Nov 16 '05 #7

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

Similar topics

8
by: vince | last post by:
I have a windows app whose main dialog contains a button that launches a form. I've tried using Form.Show() to have it launch as a modeless form, but it behaves as if it's modal (i.e. parent form...
6
by: nadeem_far | last post by:
Hello All, I am working on a .Net desktop application and I am having problem displaying a form. I am using C# and version 1.1 of the framework. here is how the code looks likes and I will...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
1
by: andrew | last post by:
Hi there, I'm having a problem with a modeless form in my app. I have a main form in my app and a socket that waits on data from a server (I use BeginReceive/EndReceive for that) and when I...
2
by: proit_123 | last post by:
I am working on a windows forms application and have the following requirement. · I need to display a modeless dialog from the main form. o This allows user to continue to work with the...
4
by: GVN | last post by:
Hi, I have two projects in my solution explorer. Say ProjA, ProjB. In ProjA I have a form called ProjAForm. In ProjB I have another form called ProjBForm. Now in ProjAForm, under a button click,...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
4
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
I am trying to close/dispose multiple instances of a form but because they are modal and hidden, they do not show up in My.Application.OpenForms. They must be modal, so making them modeless is not...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.