473,604 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Close a MDI Child form during load?

Tom
Is there ANY easy way to close a MDI Child form in the middle of it's load?
For instance, during the Load event I find a need to close the form (for
whatever reason - maybe the user isn't ready for it yet, or it displays
another form and they hit cancel). In any event, I need to be able to cause
that MDI Child form to close. Just sticking Me.Close in there won't work,
generates an error (note however, that on a NON-MDI form this seems to work
fine - go figure). I thought I could 'catch' the error in an error block
from the main MDI form; that does work - however, it must leave something
open because trying to close the main MDI form after this by using the X
button in the title bar no longer works.

Any suggestions?

Tom
Nov 20 '05 #1
6 6642
* "Tom" <to*@nospam.com > scripsit:
Is there ANY easy way to close a MDI Child form in the middle of it's load?


No. You can throw an exception to close the form, but I am sure that
there is a better solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Tom
What event, if any, runs AFTER the load is complete? If I can find something
there maybe I can set up variable to trigger a close in that event, once the
load is complete.

Tom

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2i******** ****@uni-berlin.de...
* "Tom" <to*@nospam.com > scripsit:
Is there ANY easy way to close a MDI Child form in the middle of it's
load?
No. You can throw an exception to close the form, but I am sure that
there is a better solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3
Tom
I figured out one way, but it has to be the STUPIDEST way I have ever seen!

1. Put a timer on the form and set the timer to 100 and disabled
2. When you need to close the form in the load event:
a. Move the form off the screen (me.left=-20000)
b. Enable the timer
c. Exit the load sub
3. In the timer Tick event, close the form (i.e. Me.Close)

You will get a quick flash of the scroll bars as the window is moved off the
boundries of the form and closed, but it does work.

There has GOT to be a better way to close an MDI child form during the
load!! What happens if you find an error in the load (like if reading a
database and no records show up) but you DON'T want the whole application to
shut down - just to show an error message and then close the MDI child form?
Again, there has to be an easier or cleaner method than the above way.

Anyone got ANY ideas?

Tom
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2i******** ****@uni-berlin.de...
* "Tom" <to*@nospam.com > scripsit:
Is there ANY easy way to close a MDI Child form in the middle of it's
load?
No. You can throw an exception to close the form, but I am sure that
there is a better solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
Tom,

I would suggest to reconsider. Suppose user opens MDI child and Load
encounters errors. You close form and don't give a chance to user to see
what was the reason. Possibly cleaner solution would be to open form and
display it's status - valid information error or whatever. Form can invoke
event in parent window to pass back fail / success indicator too. And main
window might close it without such hacks. Otherwise you might incite user to
click and click, until he/she figures that something is wrong and complains
about your application.

HTH
Alex

"Tom" <to*@nospam.com > wrote in message
news:u7******** ******@TK2MSFTN GP09.phx.gbl...
I figured out one way, but it has to be the STUPIDEST way I have ever seen!
1. Put a timer on the form and set the timer to 100 and disabled
2. When you need to close the form in the load event:
a. Move the form off the screen (me.left=-20000)
b. Enable the timer
c. Exit the load sub
3. In the timer Tick event, close the form (i.e. Me.Close)

You will get a quick flash of the scroll bars as the window is moved off the boundries of the form and closed, but it does work.

There has GOT to be a better way to close an MDI child form during the
load!! What happens if you find an error in the load (like if reading a
database and no records show up) but you DON'T want the whole application to shut down - just to show an error message and then close the MDI child form? Again, there has to be an easier or cleaner method than the above way.

Anyone got ANY ideas?

Tom
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2i******** ****@uni-berlin.de...
* "Tom" <to*@nospam.com > scripsit:
Is there ANY easy way to close a MDI Child form in the middle of it's

load?

No. You can throw an exception to close the form, but I am sure that
there is a better solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #5
* "Tom" <to*@nospam.com > scripsit:
What event, if any, runs AFTER the load is complete? If I can find something
there maybe I can set up variable to trigger a close in that event, once the
load is complete.


Why do you show the form? Why display it if there is a problem? Add
the code to the form's constructor ('Sub New') and throw an exception
there to cancel construction of the instance.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
"Tom" <to*@nospam.com > schrieb
Is there ANY easy way to close a MDI Child form in the middle of it's
load? For instance, during the Load event I find a need to close the
form (for whatever reason - maybe the user isn't ready for it yet, or
it displays another form and they hit cancel). In any event, I need
to be able to cause that MDI Child form to close. Just sticking
Me.Close in there won't work, generates an error (note however, that
on a NON-MDI form this seems to work fine - go figure). I thought I
could 'catch' the error in an error block from the main MDI form;
that does work - however, it must leave something open because trying
to close the main MDI form after this by using the X button in the
title bar no longer works.

Any suggestions?

Move the code out of Form_Load and execute it before showing the form. Show
the Form only if the code was successful.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7

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

Similar topics

2
18698
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:
0
1264
by: clu82 | last post by:
I have an MDI app that allows the user to open multiple client address child forms. The user has a child form open that has client id "1001" and the records associated data displayed. If the user chooses to open a new child form and then try to select client id "1001" again, I would like to automatically close this form and bring the other form that already had client "1001" to the front. With the code below, I can find the correct...
1
4218
by: Martin Douglas | last post by:
Hey guys, maybe someone can help me with some MDI issues I have. A co-worker asked me a very simple question, one that I blew off as trivial, and it has become a time-consuming issue. Simply put, there is an MDIForm and a child form. The MDIForm does the usual from within its constructor... this.IsMdiContainer = true; Form2 frm = new Form2();
8
4926
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender, System.EventArgs e) { MessageBox.Show("keyboard button pressed!"); } Following is the code to load the frmTestBaby
2
2900
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...
0
486
by: Bill | last post by:
Hi I have a parent child forms. I want the close, maximize, and minimize buttons to be removed. One the child form I have set the maximize and minimize buttons to false. I have the child form mamiximze in the parent form. So then the maximized button is still active. But I want the child form to fill the parent form without the ability to close minimize or maximize the form like a default page.
2
5644
by: Nice Chap | last post by:
I get this exception when I call Me.Close on Load event of a Form. The form producing the error is an MDI child of another form. Any ideas how I can get over this problem please. I have tried doing Me.Close on HandleCreated and Activated events but get the same exception.
2
6441
by: Michael | last post by:
Hi, I have a form (switchboard like form) thats loaded into a MDI parent form. This form is the start off point for all the other screens in the app. I have placed a exit button on the switchboard and would like to use it to close all app down. What is the best way to do that? I have the following code but it won't close the MDI parent form. for each frm as Form in MdiParent.MdiChildren frm.Close Next MdiParent.Close >> Errors on this...
4
2443
by: Maarten | last post by:
Hi I'm trying to make something i tought is was simple if i press the cross on the childform to close it, i want it to hide. but when i press a button on the parrent i want to close the child. so on the child i made a formclosing handler an in the handler i put: this.hide();
0
7929
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,...
0
8409
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8065
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
8280
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6739
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...
0
5441
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
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...
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.