473,414 Members | 1,713 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,414 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 3208
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...

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.