dr dat tran - week 1 lecture notes 1 windows forms programming graphical user interfaces pg (7110)...

16
Dr Dat Tran - Week 1 Lectur Dr Dat Tran - Week 1 Lectur e Notes e Notes 1 Windows Forms Windows Forms Programming Graphical User Interfaces PG Programming Graphical User Interfaces PG (7110) (7110) University of Canberra University of Canberra School of Information Sciences & School of Information Sciences & Engineering Engineering

Upload: harvey-ray

Post on 12-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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

Page 2: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 22

VS.NET 2005 Start PageVS.NET 2005 Start Page

Page 3: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 33

Windows ApplicationWindows Application

Page 4: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 44

Windows Application ProjectWindows Application Project

Page 5: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 55

Form PropertiesForm Properties

Page 6: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 66

Build & Debug ProjectBuild & Debug Project

Page 7: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 77

Program.cs FileProgram.cs File

Page 8: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 88

MainForm.Designer.cs FileMainForm.Designer.cs File

Page 9: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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

Page 10: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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

Page 11: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1111

Write Code in Program.csWrite Code in Program.cs

Page 12: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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

Page 13: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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()

Page 14: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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(); }}

Page 15: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

Dr Dat Tran - Week 1 Lecture NotesDr Dat Tran - Week 1 Lecture Notes 1515

Message BoxMessage Box

Page 16: Dr Dat Tran - Week 1 Lecture Notes 1 Windows Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences

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(); }}}}