Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences & Engineering
Dr Dat Tran - Week 1 Lecture Notes 2 VS.NET 2005 Start Page
Dr Dat Tran - Week 1 Lecture Notes 3 Windows Application
Dr Dat Tran - Week 1 Lecture Notes 4 Windows Application Project
Dr Dat Tran - Week 1 Lecture Notes 5 Form Properties
Dr Dat Tran - Week 1 Lecture Notes 6 Build & Debug Project
Dr Dat Tran - Week 1 Lecture Notes 7 Program.cs File
Dr Dat Tran - Week 1 Lecture Notes 8 MainForm.Designer.cs File
Dr Dat Tran - Week 1 Lecture Notes 9 Change Some Properties Try StartPosition & Location properties
Dr Dat Tran - Week 1 Lecture Notes 10 StartPosition - FormBorderStyle CentreParent only for modal dialogs (to prevent multi-monitor confusion) CentreScreen only for the main form or a splash screen WindowsDefaultLocation for everything else, to prevent windows from appearing on top of one another FixedDialog only for modal dialog boxes FixedSingle only for the main form None for splash screen Sizable for everything else, almost all forms in an application should be resizable
Dr Dat Tran - Week 1 Lecture Notes 11 Write Code in Program.cs
Dr Dat Tran - Week 1 Lecture Notes 12 Write Code in MainForm.Designer.cs
Dr Dat Tran - Week 1 Lecture Notes 13 Add a New Form At design time At run time Double-click on the form to add the Load event handler and modify it as follows Try ShowDialog()
Dr Dat Tran - Week 1 Lecture Notes 14 Example: partial class public partial class MainForm : Form public partial class MainForm : Form { public MainForm() { public MainForm() { InitializeComponent(); InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { private void MainForm_Load(object sender, EventArgs e) { f2.ShowDialog(); f2.ShowDialog(); } } public partial class MainForm : Form public partial class MainForm : Form { Form f2 = new Form(); Form f2 = new Form(); }
Dr Dat Tran - Week 1 Lecture Notes 15 Message Box
Dr Dat Tran - Week 1 Lecture Notes 16 Use DialogResult private void MainForm_Load(object sender, EventArgs e) { DialogResult ds = MessageBox.Show("Hello World", "PGUI", DialogResult ds = MessageBox.Show("Hello World", "PGUI", MessageBoxButtons.YesNoCancel); MessageBoxButtons.YesNoCancel); if (ds == DialogResult.Yes) if (ds == DialogResult.Yes) { f2.Text = "Yes"; f2.Text = "Yes"; f2.ShowDialog(); f2.ShowDialog(); } if (ds == DialogResult.No) if (ds == DialogResult.No) { f2.Text = "No"; f2.Text = "No"; f2.ShowDialog(); f2.ShowDialog(); }}