Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Dr Dat Tran - Week 2 Lecture Notes 1 Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences & Engineering."— Presentation transcript:

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

2 Dr Dat Tran - Week 2 Lecture Notes 2 Create a Shape Form public TestForm () { InitializeComponent(); System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath(); shape.AddEllipse(0, 0, this.Width, this.Height); this.Region = new System.Drawing.Region(shape); }

3 Dr Dat Tran - Week 2 Lecture Notes 3 Get a Value from Another Form In Form 1 private Form2 form2 = new Form2(); private void GetLabelControlInForm2() { label1.Text = form2.Label2.Text; } In Form 2 public Label Label2 { get { return label2; }

4 Dr Dat Tran - Week 2 Lecture Notes 4 Form Events Load: Occurs before a form is displayed for the first time Activate: Occurs when the form is activated in code or by the user Deactivate: Occurs when the form loses focus and is no longer the active form Closing: Occurs when the form is closing Closed: Occurs when the form is closed Shown: Occurs whenever the form is first displayed SizeChanged: Occurs when the Size property value changes

5 Dr Dat Tran - Week 2 Lecture Notes 5 Create a Form Event Handler double-click click private void MDIForm_Load(object sender, EventArgs e) { }

6 Dr Dat Tran - Week 2 Lecture Notes 6 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()

7 Dr Dat Tran - Week 2 Lecture Notes 7 Owner and Owned Forms If ShowDialog() is used: –Currently active form: Owner form –New form: Owned form Show() does not establish an implicit owner- owned relationship. In the modeless case, establish the relationship as follows: OwnedForm ownedForm = = new OwnedForm(); ownedForm.Owner = this;

8 Dr Dat Tran - Week 2 Lecture Notes 8 Owner and Owned Forms private Color colour = Color.Yellow;... private void ChangeColorButton_Click(object sender, EventArgs e) { colour = Color.Red; } public Color Colour { get { return colour; }

9 Dr Dat Tran - Week 2 Lecture Notes 9 Owner and Owned Forms OwnedForm owned; public OwnerForm() { InitializeComponent(); owned = = new OwnedForm(); owned.Owner = this; owned.Show(); panel1.BackColor = owned.Colour; } private void UpdateButton_Click(object sender, EventArgs e) { panel1.BackColor = owned.Colour; }

10 Dr Dat Tran - Week 2 Lecture Notes 10 Message Box

11 Dr Dat Tran - Week 2 Lecture Notes 11 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(); }}

12 Dr Dat Tran - Week 2 Lecture Notes 12 Visual Inheritance To allow a base class to capture common user interface controls Base form serves as base class Inherited form serves as derived class class InheritedForm : Forms.BaseForm Some issues may arise with regard to event handlers being called twice, because each event is being handled by both the base class and the inherited class

13 Dr Dat Tran - Week 2 Lecture Notes 13 Multiple-Document Interface (MDI) To display multiple documents at the same time Each document displayed in its own window. MDI applications often have a menu item with submenus for switching between windows or documents The Opacity property does not affect the appearance of MDI child forms. The CenterToParent method does not affect the behavior of MDI child forms

14 Dr Dat Tran - Week 2 Lecture Notes 14 Create MDI Create a new Windows form Set IsMdiContainer to true (Should set WindowState to Maximized)

15 Dr Dat Tran - Week 2 Lecture Notes 15 Add Child Forms to MDI public partial class MDIForm : Form { public MDIForm() public MDIForm() { InitializeComponent(); InitializeComponent(); Form mdiChild1 = new Form(); Form mdiChild1 = new Form(); mdiChild1.MdiParent = this; mdiChild1.MdiParent = this; mdiChild1.Show(); mdiChild1.Show(); Form mdiChild2 = new Form(); Form mdiChild2 = new Form(); mdiChild2.MdiParent = this; mdiChild2.MdiParent = this; mdiChild2.Show(); mdiChild2.Show(); } }


Download ppt "Dr Dat Tran - Week 2 Lecture Notes 1 Forms Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences & Engineering."

Similar presentations


Ads by Google