dr dat tran - week 1 lecture notes 1 windows forms programming graphical user interfaces pg (7110)...
TRANSCRIPT
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 11
Windows FormsWindows Forms
Programming Graphical User Interfaces PG (7110)Programming Graphical User Interfaces PG (7110)
University of CanberraUniversity of CanberraSchool of Information Sciences & EngineeringSchool of Information Sciences & Engineering
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 22
VS.NET 2005 Start PageVS.NET 2005 Start Page
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 33
Windows ApplicationWindows Application
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 44
Windows Application ProjectWindows Application Project
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 55
Form PropertiesForm Properties
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 66
Build & Debug ProjectBuild & Debug Project
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 77
Program.cs FileProgram.cs File
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 88
MainForm.Designer.cs FileMainForm.Designer.cs File
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 99
Change Some PropertiesChange Some Properties
Try Try StartPositionStartPosition & & LocationLocation properties properties
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1010
StartPosition - FormBorderStyle StartPosition - FormBorderStyle CentreParentCentreParent only for modal dialogs (to prevent only for modal dialogs (to prevent multi-monitor confusion) multi-monitor confusion) CentreScreenCentreScreen only for the main form or a splash only for the main form or a splash screen screen WindowsDefaultLocationWindowsDefaultLocation for everything else, to for everything else, to prevent windows from appearing on top of one prevent windows from appearing on top of one anotheranother
FixedDialogFixedDialog only for modal dialog boxes only for modal dialog boxes FixedSingleFixedSingle only for the main form only for the main form NoneNone for splash screen for splash screen SizableSizable for everything else, almost all forms in an for everything else, almost all forms in an application should be resizableapplication should be resizable
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1111
Write Code in Program.csWrite Code in Program.cs
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1212
Write Code in MainForm.Designer.csWrite Code in MainForm.Designer.cs
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1313
Add a New FormAdd a New Form
At design timeAt design time
At run timeAt run timeDouble-click on the form to add Double-click on the form to add
the Load event handler and the Load event handler and modify it as followsmodify it as follows
Try ShowDialog()Try ShowDialog()
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1414
Example: Example: partialpartial class class public public partialpartial class MainForm : Form 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 public partialpartial class MainForm : Form class MainForm : Form {{ Form f2 = new Form(); Form f2 = new Form(); }}
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1515
Message BoxMessage Box
Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1616
Use DialogResult Use DialogResult private void MainForm_Load(object sender, EventArgs e)private void MainForm_Load(object sender, EventArgs e){{ DialogResultDialogResult ds = MessageBox.Show("Hello World", "PGUI", ds = MessageBox.Show("Hello World", "PGUI", MessageBoxButtons.YesNoCancel);MessageBoxButtons.YesNoCancel); if (ds == if (ds == DialogResult.YesDialogResult.Yes)) {{ f2.Text = "Yes";f2.Text = "Yes"; f2.ShowDialog();f2.ShowDialog(); }} if (ds == if (ds == DialogResult.NoDialogResult.No)) {{ f2.Text = "No";f2.Text = "No"; f2.ShowDialog();f2.ShowDialog(); }}}}