Date post: | 06-Apr-2017 |
Category: |
Technology |
Upload: | sami-mut |
View: | 14 times |
Download: | 0 times |
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 1
Chapter 24
How to enhance the user interface
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 2
Objectives Applied 1. Use the Tab control to organize an application. 2. Use a multiple-document interface for an application. 3. Add menus, toolbars, and help information to an application.
Knowledge 1. Distinguish between a single-document and a multiple-
document interface.
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 3
Single-document interface (SDI)
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 4
Multiple-document interface (MDI)
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 5
A startup form for the Financial Calculations application
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 6
Code that displays a new instance of a form private void btnFutureValue_Click(object sender, System.EventArgs e) { Form newForm = new frmFutureValue(); newForm.Show(); }
Code that exits the application and closes all forms
private void btnExit_Click(object sender, System.EventArgs e) { Application.Exit(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 7
Code that closes the current instance of a form private void btnClose_Click(object sender, System.EventArgs e) { this.Close(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 8
A form that uses a Tab control with two tabs
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 9
Code that uses the SelectedIndex property of the Tab control
private void btnCalculate_Click(object sender, System.EventArgs e) { if (tabCalculations.SelectedIndex == 0) DisplayFutureValue(); else if (tabCalculations.SelectedIndex == 1) DisplayDepreciation(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 10
Code that uses the SelectedIndexChanged event of the Tab control
private void tabCalculations_SelectedIndexChanged( object sender, System.EventArgs e) { if (tabCalculations.SelectedIndex == 0) txtMonthlyInvestment.Focus(); else if (tabCalculations.SelectedIndex == 1) txtInitialCost.Focus(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 11
The start of the menu for the Future Value app
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 12
The complete Action menu
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 13
Common menu item properties Text Name Checked Enabled Visible ShortcutKeys ShowShortcutKeys
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 14
Code for a menu item that clears four controls private void mnuClear_Click(object sender, System.EventArgs e) { txtMonthlyInvestment.Text = ""; txtInterestRate.Text = ""; txtYears.Text = ""; txtFutureValue.Text = ""; }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 15
Code for a menu item that calls another event handler
private void mnuCalculate_Click(object sender, System.EventArgs e) { btnCalculate_Click(sender, e); }
Another way to call another event handler private void mnuCalculate_Click(object sender, System.EventArgs e) { btnCalculate.PerformClick(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 16
A project with one parent and two child forms
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 17
Properties and methods for a parent form Property/Method Description IsMdiContainer At design-time, set this property to true. ActiveMdiChild At runtime, you can use this property to
retrieve a reference to the active child form. LayoutMdi(mdiLayout) At runtime, you can use this method to
arrange all child forms by specifying a member of the MdiLayout enumeration: Cascade, TileVertical, TileHorizontal, and so on.
Typical property setting for a child form Property Description MdiParent At runtime, you can set this property to specify the
parent form for a child form.
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 18
An MDI application with three child forms arranged vertically
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 19
Code that creates and displays a new instance of a child form
private void mnuNewFutureValue_Click(object sender, System.EventArgs e) { Form newForm = new frmFutureValue(); newForm.MdiParent = this; newForm.Show(); }
Code that refers to the active child form private void mnuClose_Click(object sender, System.EventArgs e) { Form activeForm = this.ActiveMdiChild; if (activeForm != null) activeForm.Close(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 20
Code that arranges the child forms vertically private void mnuTileVertical_Click(object sender, System.EventArgs e) { this.LayoutMdi(MdiLayout.TileVertical); }
Code that exits the application and closes all child forms
private void mnuExit_Click(object sender, System.EventArgs e) { Application.Exit(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 21
A ToolStrip with the standard items
A ToolStrip with two custom buttons
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 22
The Items Collection Editor for a ToolStrip
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 23
Code for the Click event of a button on a ToolStrip private void btnFutureValue_Click(object sender, EventArgs e) { mnuNewFutureValue.PerformClick(); }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 24
A View menu that shows or hides the toolbar
Code that shows or hides a toolbar depending on a menu selection
private void mnuToolbar_Click(object sender, System.EventArgs e) { if (mnuToolbar.Checked == true) { mnuToolbar.Checked = false; tlbMain.Visible = false; } else if (mnuToolbar.Checked == false) { mnuToolbar.Checked = true; tlbMain.Visible = true; } }
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 25
A tool tip Context-sensitive help
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 26
How to work with a tool tip A tool tip is a brief description of a control that’s displayed
automatically when you place the mouse pointer over that control. To create tool tips for a form, add a ToolTip control to the form.
A control named toolTip1 will appear in the Component Designer tray at the bottom of the window.
The ToolTip control makes a property named “ToolTip on toolTip1” available for each control on the form and for the form itself. You can enter the text for the tool tip in this property.
Murach’s C# 2010, C24 © 2010, Mike Murach & Associates, Inc. Slide 27
How to work with context-sensitive help To provide context-sensitive help for a form or control, add a
HelpProvider control to the form. A control named helpProvider1 will appear in the Component Designer tray at the bottom of the window. This control makes several additional properties available for the form and each control it contains.
To display a text string when the user presses the F1 key for the control that has the focus, enter the text for the “HelpString on helpProvider1” property of the control.
You can also enter help text for the HelpString property of the form. Then, that text is displayed at the location of the mouse pointer if a help string isn’t specified for the control that has the focus.
When you enter text for the “HelpString on helpProvider1” property, the “ShowHelp on helpProvider1” property automatically changes from false to true.