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

Visible = False on Form_Closing...

Hi,

I have a MDIForm with some MDIChilds. When the user clicks on the "x" in the
upper right corner, I don't want the MDIChild to be closed, but the property
Visible = False.

So far no problem: I do this useing the Form_Closing-event in which I typed:
e.Cancel = True
Me.Visibible = False

But: When I Close the MDIParent, it wont shut down the whole application
because of the fact that those MDIChilds cancel the closing!

I tryed to put work with a boolean which is set to true when MDIParent is
closed, and first evaluated in the MIDChild_Closing-event, but that doesn't
work either, because of the fact that the Closing-event of the MDIChilds are
fired before the Closing Event of the Parent...

Anybody got any idea how to do this? Maybe with the Closed-event? This event
comes after the Closing-event, but I can't find someting in ot to Cancel the
closing of the form.

I guess there must be a 'nicer' way to do this: Maybe by handling the click
on the "x", and when it is clicked not to close etc etc...

Hoping for your help and thanks a lot in advance,

Pieter
Nov 20 '05 #1
5 3505
You can set closeing flag in the main form (MDI parent).

in the Main form (MDI parent) class:

public class frmMain:Form
{
private bool mClosing=false;
public frmMain()
{
}

internal bool MainFormClosing
{
get { return mClosing; }
}
.....
......
private void frmMain_Closing(...)
{
mClosing=true;
}
}

in the MDI child form class

public frmChild:Form
{
....
....
private frmChild_Closing(....)
{
//If the closing is caused by MDI parent, no CANCELLING
frmMain f=(frmMain)this.Parent;
if (f.MainFormClosing) return;

//Cancel closing
e.Cancel=true
this.Visible=false;
}
}

The code is in C#, and very little differentce from VB.NET code and you
should be able to read it.

HTH

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:3f**********************@news.skynet.be...
Hi,

I have a MDIForm with some MDIChilds. When the user clicks on the "x" in the upper right corner, I don't want the MDIChild to be closed, but the property Visible = False.

So far no problem: I do this useing the Form_Closing-event in which I typed: e.Cancel = True
Me.Visibible = False

But: When I Close the MDIParent, it wont shut down the whole application
because of the fact that those MDIChilds cancel the closing!

I tryed to put work with a boolean which is set to true when MDIParent is
closed, and first evaluated in the MIDChild_Closing-event, but that doesn't work either, because of the fact that the Closing-event of the MDIChilds are fired before the Closing Event of the Parent...

Anybody got any idea how to do this? Maybe with the Closed-event? This event comes after the Closing-event, but I can't find someting in ot to Cancel the closing of the form.

I guess there must be a 'nicer' way to do this: Maybe by handling the click on the "x", and when it is clicked not to close etc etc...

Hoping for your help and thanks a lot in advance,

Pieter

Nov 20 '05 #2
Unfortunately this doesn't work... I tryed it myself alreaddy before.
This code does the following: It first hides one MDIChild, and when you
click a second time on the "x" of the Parent, then it closes the whole
application.

The reason for that is simple: When you close your application, the
MIDChild_Closing-event is fired before the Parent_Closing-event: so you
aren't able to change the boolean-value before closing the MDIChilds. The
second time you click the boolean value is alreaddy changed (from the first
time), and than the application is properly shutted down.

The order of events is this:
Child_Closing
Parent_Closing
Child_Closed
Parent_Closed

So what I could do is: change the boolean in the Parent_Closing, and
evaluate it in the Child_Closed. Unfortunately: I can't find a way to cancel
the closing in the Closed-event...

Anybody any idea? I'm really stuck with this problem :-(

Pieter

"Norman Yuan" <no********@RemoveThis.shaw.ca> wrote in message
news:7jXKb.15406$JQ1.5606@pd7tw1no...
You can set closeing flag in the main form (MDI parent).

in the Main form (MDI parent) class:

public class frmMain:Form
{
private bool mClosing=false;
public frmMain()
{
}

internal bool MainFormClosing
{
get { return mClosing; }
}
.....
......
private void frmMain_Closing(...)
{
mClosing=true;
}
}

in the MDI child form class

public frmChild:Form
{
....
....
private frmChild_Closing(....)
{
file://If the closing is caused by MDI parent, no CANCELLING
frmMain f=(frmMain)this.Parent;
if (f.MainFormClosing) return;

file://Cancel closing
e.Cancel=true
this.Visible=false;
}
}

The code is in C#, and very little differentce from VB.NET code and you
should be able to read it.

HTH

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:3f**********************@news.skynet.be...
Hi,

I have a MDIForm with some MDIChilds. When the user clicks on the "x" in

the
upper right corner, I don't want the MDIChild to be closed, but the

property
Visible = False.

So far no problem: I do this useing the Form_Closing-event in which I

typed:
e.Cancel = True
Me.Visibible = False

But: When I Close the MDIParent, it wont shut down the whole application
because of the fact that those MDIChilds cancel the closing!

I tryed to put work with a boolean which is set to true when MDIParent is closed, and first evaluated in the MIDChild_Closing-event, but that

doesn't
work either, because of the fact that the Closing-event of the MDIChilds

are
fired before the Closing Event of the Parent...

Anybody got any idea how to do this? Maybe with the Closed-event? This

event
comes after the Closing-event, but I can't find someting in ot to Cancel

the
closing of the form.

I guess there must be a 'nicer' way to do this: Maybe by handling the

click
on the "x", and when it is clicked not to close etc etc...

Hoping for your help and thanks a lot in advance,

Pieter


Nov 20 '05 #3
Pieter,

this could be a slight suggestion: when the main form is beeing closed,
you can catch the message that orders it to close, set the value of some
public flag and then, in the closing event of the child you could check if
it is the main form beeing closed or just the mdi child beeing closed.

details:

put followind code in the main form:

public bool bClosingEventFromParent = false;
protected override void WndProc( ref Message m )
{
if ( m.Msg == (int)0x0112 ) // WM_SYSCOMMAND
if ( m.WParam == (IntPtr)0xF060 ) // SC_CLOSE
bClosingEventFromParent = true;
base.WndProc( ref m );
}

because the SC_CLOSE message is processed immediatelly after you press 'x'
in the main form, the flag will properly indicate the mdi child if it is the
main form beeing closed. and then you can react properly in the closing
event of the mdi child.

I hope this will help you,
Wiktor Zychla
Nov 20 '05 #4
Great! This worked fine!
But how did you come up with something like that? These are thing I even
didn't know they existed, hehe :-)

For others thare are interested in the VB.NET version:

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = Convert.ToInt32("0x0112", 16) Then
If IntPtr.op_Equality(m.WParam,
IntPtr.op_Explicit(Convert.ToInt32("0xF060", 16))) Then
blnMainClosing = True
End If
End If
MyBase.WndProc(m)
End Sub
"Wiktor Zychla" <ie****@microsoft.com.no.spam> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
Pieter,

this could be a slight suggestion: when the main form is beeing closed, you can catch the message that orders it to close, set the value of some
public flag and then, in the closing event of the child you could check if
it is the main form beeing closed or just the mdi child beeing closed.

details:

put followind code in the main form:

public bool bClosingEventFromParent = false;
protected override void WndProc( ref Message m )
{
if ( m.Msg == (int)0x0112 ) // WM_SYSCOMMAND
if ( m.WParam == (IntPtr)0xF060 ) // SC_CLOSE
bClosingEventFromParent = true;
base.WndProc( ref m );
}

because the SC_CLOSE message is processed immediatelly after you press 'x' in the main form, the flag will properly indicate the mdi child if it is the main form beeing closed. and then you can react properly in the closing
event of the mdi child.

I hope this will help you,
Wiktor Zychla

Nov 20 '05 #5
> Great! This worked fine!
But how did you come up with something like that? These are thing I even
didn't know they existed, hehe :-)


Windows GUI works by exchanging messages between visual objects. they are
triggered by various events (for example: user activity). there are however
much more win32 messages than .NET events. in such cases you just have to
know what message corresponds to the activity you would like to intercept
(or invoke).

Regards, Wiktor
Nov 20 '05 #6

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

Similar topics

6
by: Supra | last post by:
I have 8 panels control on right side uing treeview control. this will work in vb6 but can't figuring in vb.net. and i got error Sub PanelVisible(ByVal szPanel As String) Dim i As Integer,...
18
by: Stanley J Mroczek | last post by:
I Set the EditCommandColumn to Visible=False to stop people who are not allowed to make any changes to a record. How can set it to Visible=true for some users? Please answer in VB Thanks Stan
0
by: Eric J Owens | last post by:
Thanks and Hello to you! I have a form in A2k that has a tab control on it. The form opens the first page and filters the records I want just fine. When I click a tab, to view another set of...
3
by: Susan Bricker | last post by:
Greetings. I have three forms that are open at the same time. They are related and cascading. The first form (frmEventAdd) is the anchor. Each event can have many Trials. The second form is...
6
by: Marc Robitaille | last post by:
Hello, Hello, I developed a UserControl. It has funny behavior. It is composed of three controls. A texbox, a combobox and a button. There are three properties to indicate the visibility of...
2
by: aharding | last post by:
I have fields that are set to be visible or not visible based on the value of another field. These results are displayed in a continuous subform. It works fine except that it only displays the...
8
by: Doc John | last post by:
I have an MDI container with a child Form which will be visible according to certain events. The problem is that when I set the property Visible to False and then back to True, the Form will be in...
3
by: =?Utf-8?B?RnJlZHJpaw==?= | last post by:
Hi I have a problem in one of my user controls that I cannot find any solution for. I'am running C# for Visual studio 2003 and developing a windows application. The problem is the following: I...
8
by: Dan | last post by:
Hi, i experimented with postback and viewstate. With this code, there are 2 dropdownlists created, one visible and with AutoPostBack true, the other not visible and no AutoPostBack, and one...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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...
0
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
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,...

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.