Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphical User Interfaces Part 2

Similar presentations


Presentation on theme: "Graphical User Interfaces Part 2"— Presentation transcript:

1 Graphical User Interfaces Part 2
Outline Introduction Menus LinkLabels

2 Continues study of Graphical User Interface Explores:
Introduction Continues study of Graphical User Interface Explores: Menus LinkLabels

3 Menus Menu Disabled command Separator bar Checked menu item
Shortcut key Menu submenu Disabled command Separator bar Checked menu item Expanded and checked menus.

4 Group related commands together Contain:
Menus Group related commands together Contain: Commands Submenus Some commends, such as Exit are common to many applications and uses Application class to quit To create a menu drag a MenuStrip control onto form. Creates a menu bar on top of the form and an icon beneath it Click the icon Menu Designer Every option has its own event handler

5 Menus Place & character before the letter to be underlined
Text boxes used to add items to menu Menu Designer MainMenu icon Visual Studio .NET Menu Designer.

6 Menus Default Event MenuStrip Properties Menu Item Properties
MenuItems RightToLeft Menu Item Properties Text Index (position in parent list) ShortCutKeys and ShowShortCutKeys MenuItems (for a submenu) Checked (according to property RadioCheck - default is false) MergeAction (Append, Insert, Remove and Replace) MergeIndex(set position of menu item when menus are merged) Default Event Click – generated when item is clicked or shortcut key is used

7

8 11 public class MenuTest : System.Windows.Forms.Form 12 {
12 { // display label private System.Windows.Forms.Label displayLabel; 15 // main menu (contains file and format menu) private System.Windows.Forms.MainMenu mainMenu; 18 // file menu private System.Windows.Forms.MenuItem fileMenuItem; private System.Windows.Forms.MenuItem aboutMenuItem; private System.Windows.Forms.MenuItem exitMenuItem; 23 // format menu private System.Windows.Forms.MenuItem formatMenuItem; 26 // color submenu private System.Windows.Forms.MenuItem colorMenuItem; private System.Windows.Forms.MenuItem blackMenuItem; private System.Windows.Forms.MenuItem blueMenuItem; private System.Windows.Forms.MenuItem redMenuItem; private System.Windows.Forms.MenuItem greenMenuItem; options

9 private void aboutMenuItem_Click( object sender, System.EventArgs e )
// display MessageBox private void aboutMenuItem_Click( object sender, System.EventArgs e ) { MessageBox.Show( "This is an example\nof using menus.", "About", MessageBoxButtons.OK, MessageBoxIcon.Information ); } // exit program private void exitMenuItem_Click( Application.Exit(); About event handler Exit event Handler

10 private void ClearColor() { // clear all checkmarks
// reset color private void ClearColor() { // clear all checkmarks blackMenuItem.Checked = false; blueMenuItem.Checked = false; redMenuItem.Checked = false; greenMenuItem.Checked = false; } // update menu state and color display black private void blackMenuItem_Click( object sender, System.EventArgs e ) // reset checkmarks for color menu items ClearColor(); // set color to black displayLabel.ForeColor = Color.Black; blackMenuItem.Checked = true; Black event handler

11 Displays links to other objects
LinkLabels Displays links to other objects Uses event handlers to link to right file or program Start method of Process class opens other programs Derived from class Label, inherits functionality

12 LinkLabels LinkLabel on a form
Hand image displayed when mouse cursor over a LinkLabel LinkLabel control in the design phase and in running program.

13 LinkLabels Properties Event Text
LinkArea – portion of text treated as link LinkBehavior – how link appears when mouse is over it LinkColor (before visit - default is blue) ActiveLinkColor (when link clicked – default is red) VisitedLinkColor (default is purple) LinkVisited Links (lists the LinkLabel.Link objects) Event LinkClicked (default)

14 Click on first LinkLabel to look at contents of C drive

15 Click on second LinkLabel to go to the Web Site

16 Click the third LinkLabel to open notepad

17 public partial class LinkLabelTest : Form {
// linklabels to C: drive, and Notepad private System.Windows.Forms.LinkLabel driveLinkLabel; private System.Windows.Forms.LinkLabel deitelLinkLabel; private System.Windows.Forms.LinkLabel notepadLinkLabel; // browse C:\ drive private void driveLinkLabel_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) driveLinkLabel.LinkVisited = true; System.Diagnostics.Process.Start( "C:\\" ); } C drive link Deitel website link Notepad link C drive event handler Start method to open other programs

18 // load www.deitel.com in Web broswer
private void deitelLinkLabel_LinkClicked( object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e ) { deitelLinkLabel.LinkVisited = true; System.Diagnostics.Process.Start( "IExplore", " ); } // run application Notepad private void notepadLinkLabel_LinkClicked( object sender, notepadLinkLabel.LinkVisited = true; // program called as if in run // menu and full path not needed System.Diagnostics.Process.Start( "notepad" ); Deitel website event handler Notepad event handler


Download ppt "Graphical User Interfaces Part 2"

Similar presentations


Ads by Google