473,465 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Closing a form on the Load event?

Under a certain circumstance, I want a form to display a messagebox in the
load event, and then close. But apparently I cant close a form in the load
event. Any ideas?

Thanks


Nov 15 '05 #1
5 26447
Maybe you could check for this circumstance before calling Application.Run()
or Form.Show() if it's not the main form.

Best Regards, Mikael
"David Smith" <no****@here.net> wrote in message
news:3f********@news.athenanews.com...
Under a certain circumstance, I want a form to display a messagebox in the
load event, and then close. But apparently I cant close a form in the load
event. Any ideas?

Thanks

Nov 15 '05 #2
I agree with John, it seems poorly structured.

However, that being said, it worked fine for me:
private void Form1_Load(object sender, System.EventArgs e)
{
Console.WriteLine("Form Load");
MessageBox.Show("Hi");
this.Close();
}
A better solution:
Add a method to your Form called:
public bool ShouldShow()
And use that before calling Show().

Or you could try using the VisibleChanged event. Unfortunately, in an
example I ran, the VisibleChanged event fires after the Load event

Finally, you could declare a new Show() method that either display a
message box or else calls base.Show(). Note, however, that Show is
not declared virtual, so Application.Run(myForm) will not call your
method polymorphically.

mike
"John Wood" <j@ro.com> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
It sounds like this might be more of a design issue than anything. You probably want to catch that exception (the instance where you show the messagebox rather than displaying the form) BEFORE you load the form by doing the .Show().

"David Smith" <no****@here.net> wrote in message
news:3f********@news.athenanews.com...
Under a certain circumstance, I want a form to display a messagebox in the load event, and then close. But apparently I cant close a form in the load event. Any ideas?

Thanks


Nov 15 '05 #3
Hi David,

David Smith wrote:
Under a certain circumstance, I want a form to display a messagebox in the
load event, and then close. But apparently I cant close a form in the load
event. Any ideas?


My idea is to call "Application.Exit()"
and it works...

Marcin Grzębski

Nov 15 '05 #4
"Marcin Grzębski" <mg*******@stop.spam.taxussi.com.pl> wrote in
message news:bh**********@nemesis.news.tpi.pl...
My idea is to call "Application.Exit()"
and it works...


Only if you want to completely exit the application. What about if
you just want to stop showing some child form?
Nov 15 '05 #5
"mist" <zj****@163.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
It's a bug of framework 1.0,you can use framework 1.1,
it's worked fine on framework1.1:


But I'm using framework 1.0 and everything worked fine for me.
-mike
Nov 15 '05 #6

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

Similar topics

3
by: ThunderMusic | last post by:
Hi, I'm trying to have a MSN Messenger like form/app closing behavior. When I click on the X button, I only want the form to disappear and when I double-click on the notify icon or right-click...
2
by: EH Eisenberger | last post by:
It seems a bug in access. When you open any form in MS Access XP and move to another record from where the form started, and then close the Access application, the FormLoad event will be executed...
1
by: MuZZy | last post by:
HI, I have a user control, say with one textBox. I need the following: when the user closes form (either calling Form.Close, or pressing "X" or anyhow), UserControl copies a file from a...
5
by: John | last post by:
Hi I have a main form that contains a panel which contains a child form. The problem is that when the main form is closed by the user, the 'closing' event for the child form is not triggered,...
5
by: smhaig | last post by:
In a vb 6 app in the activate event I was able to do some testing and if something failed, I was able to exit the form and return to the caller form. I have tried everything and searched web but...
2
by: chris in grimsby | last post by:
MDIChild Window Closing event not raised when MDI Parent is in a class library! Intructions to recreate problem: 1. Create a ClassLibrary project 2. Add an MDIParent form and a form that will...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
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
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...
1
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,...
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.