473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close an MDI child window

I have an MDI application that starts an instance of a child form at
application start. I have an event handler on a combo box checking
for the selected value to change. When the select value changes, I
call a method on the parent form to change some menu options, and then
I need to close the child form. My code looks something like this:

private void ddlDatabase_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
_parent.BuildMe nus();
this.Close();
}
The problem is, writing the code this way causes an exception to be
thrown at the following block of code:

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

on the parent form. I have tried a variety of things, but am not sure
of the right way to go about this.

Can someone shed some light for me?

Guy
Nov 15 '05 #1
2 9018
"Guy Babbitt" <gu*********@fs afood.com> wrote in message
news:37******** *************** ***@posting.goo gle.com...
private void ddlDatabase_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
_parent.BuildMe nus();
this.Close();
}
The problem is, writing the code this way causes an exception to be
thrown at the following block of code:


Without knowing what BuildMenus() does, have you tried putting a DoEvents()
between BuildMenus() and Close()? If BuildMenus() ends up sending messages
to the MDI children I could see why perhaps things could go awry.

-- Alan
Nov 15 '05 #2
Let me simplify it like this:

On a child MDI form I have a combo box. For the selectionchange d
event of that combo box I want to simply do a this.Close(). This
action ends up bubbling an error to the parent form with the following
exception:

System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr
wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)\r\n
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)\r\n at
System.Windows. Forms.Control.D efWndProc(Messa ge& m)\r\n at
System.Windows. Forms.Control.W mCommand(Messag e& m)\r\n at
System.Windows. Forms.Control.W ndProc(Message& m)\r\n at
System.Windows. Forms.ComboBox. WndProc(Message & m)\r\n at
System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)\r\n
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)\r\n
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)\r\n at
System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G&
msg)\r\n at System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth ods+IMsoCompone ntManager.FPush MessageLoop(Int 32
dwComponentID, Int32 reason, Int32 pvLoopData)\r\n at
System.Windows. Forms.ThreadCon text.RunMessage LoopInner(Int32 reason,
ApplicationCont ext context)\r\n at
System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)\r\n at
System.Windows. Forms.Applicati on.Run(Form mainForm)\r\n at
FSA.FoodShow.Wi n32.MDIParent.M ain() in mdiparent.cs:li ne 385
I had a hunch that this might be because I was placing the .close()
command in an event handler that was currently firing, so I took the
approach of actually creating a custom event that the parent MDI
subscribes to and then had the combo box selectionchange event call
that new event. I had the event handler for the new event then try to
close the child window, but that still thows the same error.

So, how am I supposed to have a MDI child close itself?

Any thoughts?

Guy
"Alan Pretre" <no@spam> wrote in message news:<u5******* *******@TK2MSFT NGP09.phx.gbl>. ..
"Guy Babbitt" <gu*********@fs afood.com> wrote in message
news:37******** *************** ***@posting.goo gle.com...
private void ddlDatabase_Sel ectedIndexChang ed(object sender,
System.EventArg s e)
{
_parent.BuildMe nus();
this.Close();
}
The problem is, writing the code this way causes an exception to be
thrown at the following block of code:


Without knowing what BuildMenus() does, have you tried putting a DoEvents()
between BuildMenus() and Close()? If BuildMenus() ends up sending messages
to the MDI children I could see why perhaps things could go awry.

-- Alan

Nov 15 '05 #3

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

Similar topics

1
4534
by: Joe D | last post by:
I think this is a simple question. But I am new to JS. Here is what I want to do: From a parent window, open a popup window (child) to get data from user, then user submit the request, close the child window, an ASP page is generated from server and displayed with data in parent window, rather than child window. Right now, I can display in child window. But do not know how to display in parent. TIA
2
18716
by: Irvin Amoraal | last post by:
Process: I have a form which uploads a file from client to server written in PHP. When the user presses the submit button, I use the "onSubmit" event to execute javascript to open a child window containing some text and an animated GIF. The javascript returns 'True' and the file is uploaded. All of that works great. Problem: Now I am trying to close the child window after the file has been uploaded. Below is the JavaScript I'm using:
6
1780
by: | last post by:
In IE, from the child window of a frameset i use the function top.window.close() And this works in IE, but not in nn4! How can i make this same effect in nn4? please help
28
14255
by: PerryC | last post by:
Anyone know how to auto close the parent / opener window without confirmation? I have tried: <script> opener.window.close() </script> ----I put it in the child html page, and nothing happen!!---
1
3370
by: gopal srinivasan | last post by:
I need to know how to close a parent modal window when child modal window opens, also i need to know the syntax for writing document on the modal window on the fly, like what we do in case of normal window. Actually, I tried to close the parent window from the child modal window using parent.close syntax in onload event in child modal window. It actually closes the parent modal window, but the child modal window is not opened, why it is...
3
3753
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be able to close all the opened child browser pages from the parent page. Thank you for your help, Isabel
2
2907
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open. Although the child form has a close button (with java script) if the user navigates the parent form to another form the child form is still open. Just wondering if there is a way to close the child form when the user navigates away with the parent...
3
4132
by: Volodymyr Lozovoy | last post by:
Help novice I open new window using window.open(), then user click button in this window and i create file and return it user using Response.Redirect(fileName). How i can close the window after that?
7
2513
by: Jaggu | last post by:
Hi , I need to close main window, once the child window succesfully opens else main window to remain. In my case when I close the main window immediately after the "window.open()" as mentioned below, both the main and child disappears(this is due to pop up blocker) disappears suddenly. I want to make the browser know if pop up blocks the child window(in case). help me how to check the child window opened successfuly or not, on
1
4524
by: michal.podlewski | last post by:
Hi All, I have a problem with a simple (as I thought till now) thing: I want to make a link in a child-window which would change site in the parent-window and along with closing child window. The parent window name is "main". A made a link like this in the child-site: <a href="new_address.html" target="main" class="about" onclick="javascript:main.location='new_address.html';self.close();"> change and close </a>
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8210
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
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.