































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Notes related to computer science
Typology: Study notes
1 / 39
This page cannot be seen from the preview
Don't miss anything!
Building a Main Window by Hand
(MDI) application. When you are interested in creating and displaying the main window in your program, you have two mandatory steps:
string.Format("This app brought to you by {0}", Application.CompanyName)); } } Output:
Example: public class MainWindow : Form { protected override void OnMouseDown(MouseEventArgs e) { // Add code for MouseDown event. // Call parent implementation when finished. base.OnMouseDown(e); } }
Text = string.Format("Current Pos: ({0}, {1})", e.X, e.Y); } }
public class MainForm : Form { public MainForm() { ... // Listen for the KeyUp Event. KeyUp += new KeyEventHandler(MainForm_KeyUp); } private void MainForm_KeyUp (object sender, KeyEventArgs e) { MessageBox.Show(e.KeyCode.ToString(), "Key Pressed!"); } }
{ lifeTimeInfo += "Activate event\n"; } private void MainForm_Deactivate(object sender, System.EventArgs e) { lifeTimeInfo += "Deactivate event\n"; } private void MainForm_Closed(object sender, System.EventArgs e) { lifeTimeInfo += "Closed event\n"; MessageBox.Show(lifeTimeInfo); } Within the Closing event handler, you will prompt the user to ensure she wishes to terminatethe application using the incoming CancelEventArgs: private void MainForm_Closing(object sender, CancelEventArgs e) { DialogResult dr = MessageBox.Show("Do you REALLY want to close this app?", "Closing event!", MessageBoxButtons.YesNo); if (dr == DialogResult.No) e.Cancel = true; else e.Cancel = false; }
private System.Windows.Forms.MenuStrip mainMenuStrip; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; }