Windows Develop Bookmark and Share   
 index > Windows Forms General > exiting the application
 

exiting the application

hi
i want to check the screen resolution in my code, and if the display resolution does not meet the requirements the application has to exit. so i wrote this in the constructor:

int height = Screen.PrimaryScreen.Bounds.Height;
int width = Screen.PrimaryScreen.Bounds.Width;

if (height > 768 || width > 1024){
MessageBox.Show("Error");
Application.Exit();
}

it recognizes the screen Resolution but it does'nt exit the application.why??
thanks
FMZL  Saturday, October 03, 2009 8:02 PM

Did you say you put that in the main form's constructor?
The Form.Load or Form.Shown event might be better...
Try this with your code instead of Application.Exit in the Load or Shown event.

this.Close();  // if the form has not been shown

The application will exit normally if you simply close the main form.
The form that is started by this line.

Application.Run(new MainForm());


Rudedog  =8^D


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer byFMZL Saturday, October 03, 2009 9:17 PM
  •  
Rudedog2  Saturday, October 03, 2009 8:18 PM

Did you say you put that in the main form's constructor?
The Form.Load or Form.Shown event might be better...
Try this with your code instead of Application.Exit in the Load or Shown event.

this.Close();  // if the form has not been shown

The application will exit normally if you simply close the main form.
The form that is started by this line.

Application.Run(new MainForm());


Rudedog  =8^D


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer byFMZL Saturday, October 03, 2009 9:17 PM
  •  
Rudedog2  Saturday, October 03, 2009 8:18 PM
thank you.
FMZL  Saturday, October 03, 2009 9:17 PM

You can use google to search for other answers

Custom Search

More Threads

• How to reduce flickering
• Message="Cannot set the SelectedValue in a ListControl with an empty ValueMember."
• panel.hide/show vs. panel.visible
• Passing (or accessing) arrays on one win form to another.
• WebBrowser interaction help
• Integrating MS Word in your .NET application
• I.E. Error
• print content of a control in form
• Copy+Paste Music File Data to Word from Windows Media Player
• How do you set the DefaultItem in a ContextMenuStrip?