GUI Concepts - 3. Menus Creating Other Forms Visual Inheritance Outline.

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

Objectives © Paradigm Publishing, Inc. 1 Objectives.
Chapter 1: An Introduction to Visual Basic 2012
110-H1 More VB Tools Creating a Menu: What is a menu? a group of (related) commands displayed at at the top of an application Top level menu Disabled command.
PowerPoint. Getting Started with PowerPoint Objectives Start PowerPoint and open presentations Explore toolbars and menus Use the Office Assistant Work.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
© by Pearson Education, Inc. All Rights Reserved. continued …
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
 2002 Prentice Hall. All rights reserved. 1 Chapter 13 – Graphical User Interfaces: Part 2 Outline 13.1Introduction 13.2 Menus 13.3 LinkLabel s 13.4 ListBox.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
MENUS AND THE MENU EDITOR Elements of a Menu Menu bar Menu title Separator bar Menu items.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 2 –Visual Basic, Controls, and Events
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
Multiple Forms, Standard Modules, And Menus
IE 411/511: Visual Programming for Industrial Applications
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
 2009 Pearson Education, Inc. All rights reserved Dive Into ® Visual C# 2008 Express.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Introduction to Visual Basic.NET Your First Visual Basic.NET Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
 2002 Prentice Hall. All rights reserved. 1 Chapter 13 – Graphical User Interfaces: Part 2 Outline 13.1Introduction 13.2 Menus 13.3 LinkLabel s 13.4 ListBox.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 3.1 Test-Driving the Welcome Application 3.2.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
CSD 340 (Blum)1 Using Visual Studio CSD 340 (Blum)2 Start/Microsoft Visual Studio 2005/Microsoft Visual Studio 2005.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 8 Debugging, Creating Executable Files, and Distributing a Windows Application.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Menus Menus provide groups of related commands for windows applications Menu, menu items, submenus A menu item that contains a submenu is considered to.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Chapter 13 – GUI: Part Introduction 13.2 Menus 13.3 LinkLabel s 13.4 ListBox es and CheckedListBox es ListBoxes CheckedListBoxes.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
 2007 Pearson Education, Inc. All rights reserved Introduction to the Visual Basic Express 2005 IDE.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
 You won’t write a single line of program code.  Instead, you’ll use visual programming techniques.  Visual Studio processes your actions (such as mouse.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
Dive Into® Visual Basic 2010 Express
Multiple Forms and Menus
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
Graphical User Interfaces Part 2
Introduction to the Visual C# 2005 Express Edition IDE
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Chapter 2 – Introduction to the Visual Studio .NET IDE
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

GUI Concepts - 3

Menus Creating Other Forms Visual Inheritance Outline

Menus Menu – provides groups of related commands. Menu items – Commands or options in menu Sub-menu – Menu within a menu Hot keys – Alt key shortcuts Press Alt + underlined letter in desired menu item

Menus D C All menu items can have Alt key shortcuts which are accessed by pressing Alt and the underlined letter (for example, Alt + F expands the File menu). Some menu items display checkmarks, usually indicating that multiple options on the menu can be selected at once. Menus that are not top-level menus can have shortcut keys as well (combinations of Ctrl, Shift, Alt, F1, F2, letter keys, etc.).

Menus To create a menu, open the Toolbox and drag a MainStrip control onto the form. This creates a menu bar on the top of the form and places a MainStrip icon at the bottom of the IDE. To add command names to the menu, click the Type Here textbox and type the menu command’s name.

Menus To create an access shortcut (or keyboard shortcut), type an ampersand (&) in front of the character to be underlined. For example, to create the File menu item, type &File. Separator bars are inserted by right-clicking the menu and selecting Insert Separator or by typing “-” for the menu text.

Buttons also can have access shortcuts. Place the & symbol immediately before the desired character. To click the button, the user then presses Alt and the underlined character. It is convention to place an ellipsis (…) after a menu item that display a dialog (such as Save As...).

Menus

1 ' Fig 13.5: MenuTest.vb 2 ' Using menus to change font colors and styles. 3 4 Public Class FrmMenu 5 Private Sub mnuitmAbout_Click( _ 6 ByVal sender As System.Object, _ 7 ByVal e As System.EventArgs) Handles mnuitmAbout.Click 8 9 MessageBox.Show("This is an example" & vbCrLf & _ 10 "of using menus.", "About", MessageBoxButtons.OK, _ 11 MessageBoxIcon.Information) 12 End Sub ' mnuitmAbout_Click ' exit program 15 Private Sub mnuitmExit_Click( _ 16 ByVal sender As System.Object, _ 17 ByVal e As System.EventArgs) Handles mnuitmExit.Click Application.Exit() 20 End Sub ' mnuitmExit_Click This event handler displays a message box when the about menu item in the file menu is clicked This event handler terminates the application when the exit menu item in the file menu is clicked

21 ' reset font color 22 Private Sub ClearColor() ' clear all checkmarks 25 mnuitmBlack.Checked = False 26 mnuitmBlue.Checked = False 27 mnuitmRed.Checked = False 28 mnuitmGreen.Checked = False 29 End Sub ' ClearColor ' update menu state and color display black 32 Private Sub mnuitmBlack_Click(ByVal sender As System.Object, _ 33 ByVal e As System.EventArgs) Handles mnuitmBlack.Click ' reset checkmarks for color menu items 36 ClearColor() ' set color to black 39 lblDisplay.ForeColor = Color.Black 40 mnuitmBlack.Checked = True 41 End Sub ' mnuitmBlack_Click Each color menu item must be mutually exclusive, so each event handler calls method ClearColor

42 ' update menu state and color display blue 43 Private Sub mnuitmBlue_Click(ByVal sender As System.Object, _ 44 ByVal e As System.EventArgs) Handles mnuitmBlue.Click ' reset checkmarks for color menu items 47 ClearColor() ' set color to blue 50 lblDisplay.ForeColor = Color.Blue 51 mnuitmBlue.Checked = True 52 End Sub ' mnuitmBlue_Click ' update menu state and color display red 55 Private Sub mnuitmRed_Click(ByVal sender As System.Object, _ 56 ByVal e As System.EventArgs) Handles mnuitmRed.Click ' reset checkmarks for color menu items 59 ClearColor() ' set color to red 62 lblDisplay.ForeColor = Color.Red 63 mnuitmRed.Checked = True 64 End Sub ' mnuitmRed_Click

65 ' update menu state and color display green 66 Private Sub mnuitmGreen_Click(ByVal sender As System.Object, _ 67 ByVal e As System.EventArgs) Handles mnuitmGreen.Click ' reset checkmarks for color menu items 70 ClearColor() ' set color to green 73 lblDisplay.ForeColor = Color.Green 74 mnuitmGreen.Checked = True 75 End Sub ' mnuitmGreen_Click ' reset font type 78 Private Sub ClearFont() ' clear all checkmarks 81 mnuitmTimes.Checked = False 82 mnuitmCourier.Checked = False 83 mnuitmComic.Checked = False 84 End Sub ' ClearFont 85

86 ' update menu state and set font to Times 87 Private Sub mnuitmTimes_Click(ByVal sender As System.Object, _ 88 ByVal e As System.EventArgs) Handles mnuitmTimes.Click ' reset checkmarks for font menu items 91 ClearFont() ' set Times New Roman font 94 mnuitmTimes.Checked = True 95 lblDisplay.Font = New Font("Times New Roman", 30, _ 96 lblDisplay.Font.Style) 97 End Sub ' mnuitmTimes_Click ' update menu state and set font to Courier 100 Private Sub mnuitmCourier_Click(ByVal sender As System.Object, _ 101 ByVal e As System.EventArgs) Handles mnuitmCourier.Click ' reset checkmarks for font menu items 104 ClearFont() ' set Courier font 107 mnuitmCourier.Checked = True 108 lblDisplay.Font = New Font("Courier New", 30, _ 109 lblDisplay.Font.Style) 110 End Sub ' mnuitmCourier_Click Each font menu item must be mutually exclusive, so each event handler calls method ClearFont

' update menu state and set font to Comic Sans MS 113 Private Sub mnuitmComic_Click(ByVal sender As System.Object, _ 114 ByVal e As System.EventArgs) Handles mnuitmComic.Click ' reset check marks for font menu items 117 ClearFont() ' set Comic Sans font 120 mnuitmComic.Checked = True 121 lblDisplay.Font = New Font("Comic Sans MS", 30, _ 122 lblDisplay.Font.Style) 123 End Sub ' mnuitmComic_Click ' toggle checkmark and toggle bold style 126 Private Sub mnuitmBold_Click( _ 127 ByVal sender As System.Object, _ 128 ByVal e As System.EventArgs) Handles mnuitmBold.Click ' toggle checkmark 131 mnuitmBold.Checked = Not mnuitmBold.Checked ' use Xor to toggle bold, keep all other styles 134 lblDisplay.Font = New Font( _ 135 lblDisplay.Font.FontFamily, 30, _ 136 lblDisplay.Font.Style Xor FontStyle.Bold) 137 End Sub ' mnuitmBold_Click

' toggle checkmark and toggle italic style 140 Private Sub mnuitmItalic_Click( _ 141 ByVal sender As System.Object, _ 142 ByVal e As System.EventArgs) Handles mnuitmItalic.Click ' toggle checkmark 145 mnuitmItalic.Checked = Not mnuitmItalic.Checked ' use Xor to toggle italic, keep all other styles 148 lblDisplay.Font = New Font( _ 149 lblDisplay.Font.FontFamily, 30, _ 150 lblDisplay.Font.Style Xor FontStyle.Italic) 151 End Sub ' mnuitmItalic_Click End Class ' FrmMenu

Menus Demo

Example – Long / Short Menu

Public Class Form1 Private Sub MenuSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuSize.Click If MenuSize.Text = "Short Menu" Then MenuSize.Text = "Long Menu" Else MenuSize.Text = "Short Menu" End If mFontUnderline.Visible = Not mFontUnderline.Visible mFontStrike.Visible = Not mFontStrike.Visible mFontSmallCaps.Visible = Not mFontSmallCaps.Visible mFontAllCaps.Visible = Not mFontAllCaps.Visible End Sub

1 -Adding a New Form to the Project You can add a new form to the project with which you are working. To do that, right click on the project name>Add Select Windows Form from the window and click Add to add a new form to the project. Creating other Forms

To run the application with other Startup object: Right-click on the project name in Solution Explorer window and select Properties which displays the Property Pages window. On this window click the drop- down box which is labeled as Startup Object. Doing that displays all the forms available in the project. Select the form which you want to be displayed when you run the application. Now, when you run the application, the form you assigned as Startup object will be displayed.

2- Working with Multiple Forms

Public Class Form1 Private Sub btnFrm2_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles btnFrm2.Click Form2.Show() Me.Hide() Form3.Hide() End Sub Private Sub btnFrm3_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles btnFrm3.Click Form3.Show() Me.Hide() Form2.Hide() End Sub End Class Public Class Form2 Private Sub btnFrm1_Click(ByVal _ sender As System.Object, ByVal e As _ System.EventArgs) Handles _ btnFrm1.Click Form1.Show() Me.Hide() End Sub End Class Public Class Form3 Private Sub btnFrm1_Click(ByVal _ sender As System.Object, ByVal e As _ System.EventArgs) Handles _ btnFrm1.Click Form1.Show() Me.Hide() End Sub End Class

In OOP, Inheritance is the ability to use all of the functionality of an existing class, and extend those capabilities without re-writing the original class. In.NET, inheritance is not just limited to designing classes but also extended to visual designing. So, what does it mean? Well, it means we can use inheritance in Form designing too, so this kind of usage is called Visual Inheritance. One of the main advantages of visual inheritance is it reduces or cuts down the development time, and helps in designing consistency in the Forms layouts. Visual Inheritance

Derived forms contain same functionality as Base form including: – Properties – Methods – Variables – Controls – All visual aspects Sizing Layout Spacing Colors and fonts

1 ' Fig : FrmInheritance.vb 2 ' Form template for use with visual inheritance. 3 4 Imports System.Windows.Forms 5 6 Public Class FrmInheritance 7 Inherits Form 8 9 ' invoked when user clicks Learn More button 10 Private Sub cmdLearn_Click(ByVal sender As System.Object, _ 11 ByVal e As System.EventArgs) Handles cmdLearn.Click MessageBox.Show("Bugs, Bugs, Bugs is a product of " & _ 14 " Bug2Bug.com.", "Learn More", MessageBoxButtons.OK, _ 15 MessageBoxIcon.Information) 16 End Sub ' cmdLearn_Click End Class ' FrmInheritance lblBug lblCopyright cmdLearn Example: 1- Create the Base Form

Example: 2- Run the Base Form to make sure it runs correctly

To allow other forms to inherit from FrmInheritance, we must package FrmInheritance as a.dll. Right click the project's name in the Solution Explorer and choose Properties. Example: 3- Packaging the Base Form

Under Application > Application Type, change Type to Class Library. Building the project produces the.dll.

To visually inherit from FrmInheritance, we create an empty project. From the Project menu, select Add Inherited Form... to display the Add New Item dialog. Select Inherited Form from the Templates pane. Clicking OK displays the Inheritance Picker tool. Example: 4- Create an empty project to make the derived form

The Inheritance Picker tool enables programmers to create a form which inherits from a specified form. Click button Browse and select the.dll file corresponding to FrmInheritance. This.dll file normally is located within the project’s bin directory. Click OK. The Form Designer should now display the inherited form We can add components to the form.

In the design view Visual Studio adds Glyphs to the image to let you know that these components are inherited, not actually in this form No Glyphs, it is not inherited

1 ' Fig : VisualTest.vb 2 ' A form that uses visual inheritance. 3 4 Public Class FrmVisualTest 5 Inherits VisualForm.FrmInheritance ' invoke when user clicks Learn the Program button 9 Private Sub cmdProgram_Click(ByVal sender As System.Object, _ 10 ByVal e As System.EventArgs) Handles cmdProgram.Click MessageBox.Show( _ 13 "This program was created by Deitel & Associates", _ 14 "Learn the Program", MessageBoxButtons.OK, _ 15 MessageBoxIcon.Information) 16 End Sub ' cmdProgram_Click End Class ' FrmVisualTest Components, layout and functionality of the base form are inherited by the new form cmdProgram new button added to form Example: 5- Add new controls to the derived form

Reading Topics For more information on how to Access Controls on Other Forms: For more information on how to Use Events in Multiple Forms: