CSCI 3327 Visual Basic Chapter 10: Windows Forms GUI: A Deeper Look UTPA – Fall 2011.

Slides:



Advertisements
Similar presentations
Information System Design Lab 5&6. User Interface Design.
Advertisements

14-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
CSCI 3328 Object Oriented Programming in C# Chapter 10: Graphical User Interfaces with Windows Forms 1 Xiang Lian The University of Texas – Pan American.
Pemrograman VisualMinggu …8… Page 1 MINGGU Ke Delapan Pemrograman Visual Pokok Bahasan: Graphical User Interface Tujuan Instruksional Khusus: Mahasiswa.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Microsoft Visual C#.NET: From Problem Analysis to Program Design1 Chapter 9 Programming Based on Events Microsoft Visual C#.NET: From Problem Analysis.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Programming Based on Events
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
MDI windows Single-document-interface (SDI)
ListBoxes The list box control allows the user to view and select from multiple items in a list. CheckedListBox control extends a list box by including.
Group Boxes and Panels Arrange components on a GUI Buttons and etc. can be placed inside a group box or panel. All these buttons move together when the.
Programming Based on Events
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
1 Multiple Document Interface (MDI) Windows. Single Document Interface (SDI) A program that can only support one open window or a document For Example,
BİL528 – Bilgisayar Programlama II Advanced Controls, Menus, Toolbars, and Status Bars 1.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
1 Graphical User Interfaces Part 2 Outline ListBoxes and CheckedListBoxes ListBoxes CheckedListBoxes ComboBoxes.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
CIS 115 Lecture 3.  Forms  Form properties  Controls  Control properties  Event Driven Programming  Form Events  Control Events  Event Handlers.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
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.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
ListBox, ComboBox, Menu Chapter 5.4, ComboBox Control: Properties & Methods u Combines TextBox features with a short drop- down list  cboOne.AddItem(string)
 2009 Pearson Education, Inc. All rights reserved Graphical User Interfaces with Windows Forms.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 – Graphical User Interfaces Part 2 Outline.
Graphical User Interface Concepts - Part 2 Session 09 Mata kuliah: M0874 – Programming II Tahun: 2010.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 - Graphical User Interface Concepts: Part.
Visual C# 2012 How to Program 1. 2  A graphical user interface (GUI) allows a user to interact visually with a program.  Figure 14.1 shows a Visual.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
VB.NET Additional Topics
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
1 Chapter Eleven Handling Events. 2 Objectives Learn about delegates How to create composed delegates How to handle events How to use the built-in EventHandler.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
COM148X1 Interactive Programming Lecture 7. Topics Today HCI Event Handling.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Module 1 Window Forms – Basic, Grouping and Graphic controls 1.
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.
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:
Compound Data Types Part13dbg. 2 Point A Point is a simple built-in struct that stores a pair of screen coordinates. Instantiate a Point: Point aPoint.
DateTime, Code Regions, and Multiple Form Applications Part13dbg.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Dr. Abraham Professor UTPA Graphical User Interface.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Dive Into® Visual Basic 2010 Express
Graphical User Interface
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming UTPA – Fall 2012 This set of slides is revised from lecture.
Week 3: WINDOWS PROGRAMMING
Chapter 1: An Introduction to Visual Basic 2015
Programming Based on Events
Windows Forms GUI: A Deeper Look
Visual programming Chapter 4: GUI (Graphical User Interface) Part II
Visual C# - GUI and controls - 1
Chapter 13 Additional Topics in Visual Basic
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

CSCI 3327 Visual Basic Chapter 10: Windows Forms GUI: A Deeper Look UTPA – Fall 2011

Objectives In this chapter, you will –Learn the design of graphical user interfaces (GUIs) –Get familiar with programming mouse and keyboard events –Know how to create and manipulate controls E.g., Panel, ToolTip, Menu, MonthCalendar, LinkLabel, and CheckedListBox, 2

Controls 3

Controls and Components ToolBox A form is a container for controls and components Visual Studio generates code of controls and components when you drag them onto the form 4

Common Properties of a Form AcceptButton –Button that is clicked when Enter key is pressed AutoScroll CancelButton –Button that is clicked when Esc key is pressed FormBorderStyle Font Text 5

Common Methods & Events of a Form Methods –Close Close a form and release its resources –Hide Hide a form without releasing or destroying its resources –Show Display a hidden form Events –Load 6

Create Event Handlers In the code editor window –Select a control (e.g. button) from the left combo box –Select an event from the right combo box –Code is generated automatically 7

Control Properties and Methods Properties –TabIndex Controls receive focus in the order of TabIndex property –TabStop Prevent the control from receiving the focus in this manner –Enabled vs. Visible Methods –Focus –Hide: set Visible property to False –Show: set Visible property to True 8

GroupBoxes and Panels Properties of GroupBox –Controls –Text Properties of Panel –AutoScroll –BorderStyle –Controls 9

Example 14.12: PanelDemo.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Display the button you clicked on Panel –Hanldes Button1.Click, Button2.Click –The same method for multiple events –Ctype (sender, Button).Text 10

Tool Tips A helpful text that appears when the mouse hovers over a GUI control Drag ToolTip component to form –It appears below the form in the design mode Each control will have an extra property –ToolTip on ToolTip1 11

Mouse-Event Handling Mouse events –Clicks, presses, and moves –For most mouse events, information about the event is passed to the event-handling method by an object of class MouseEventArgs Mouse pointer's x- and y-coordinates The mouse button pressed (Right, Left or Middle) The number of times the mouse was clicked 12

Mouse-Event Handling (cont'd) Mouse events –Mouse event with event argument of type EventArgs MouseEnter, MouseLeave –Mouse event with event argument of type MouseEventArgs MouseDown, MouseHover, MouseMove, MouseUp –Class MouseEventArgs properties Button, Clicks, X, Y 13

Example 14.18: Painter.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Painter_MouseMove –e As MouseEventArgs e.X, e.Y –g As Graphics = CreateGraphics() –G.FillEllipse(New SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4) 14 (e.X, e.Y) 4 4

Keyboard-Event Handling Key Events with Event Arguments of Type KeyEventArgs –KeyDown, KeyUp Key Events with Event Arguments of Type KeyPressEventArgs –KeyPress Class KeyPressEventArgs properties –KeyChar (ASCII character for the key pressed) –Handled (indicating wether the KeyPress event was handled) Class KeyEventArgs properties –Alt, Control, Shift, Handled, KeyCode 15

Example 14.20: KeyDemo URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html ByVal e As KeyPressEventArgs –e.KeyChar ByVal e As KeyEventArgs –e.Alt, e.Shift, e.Control –e.KeyCode.ToString(), e.KeyData.ToString(), e.KeyValue.ToString() 16

Menu –Shortcut Keys Type an ampersand (&) symbol before the character to be underlined To display &, use && –To add shortcut keys for menu items Set the ShortcutKeys property –Other types of menu items Separator bar ComboBox MenuItem TextBox 17

Example 14.25: MenuTest.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html blackToolStripMenuItem.Checked = True displayLabel.Font = New Font("Times New Roman", 14, displayLabel.Font.Style) Application.Exit() 18

MonthCalendar Control Properties –FirstDayOfWeek –MaxDate, MinDate –MaxSelectionCount –SelectionRange Event –DateChanged 19

Example 14.29: DateTimePicker URL: – 10/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_20 10/codeexamples.html dropOffDateTimePicker.MinDate=DateTime.Tod ay dropOffDateTimePicker.MaxDate=DateTime.Tod ay.AddYears(1) Dim dropOffDate As DateTime = dropOffDateTimePicker.Value –dropOffDate.DayOfWeek=DayOfWeek.Friday –dropOffDate.AddDays(3).ToLongDateString() 20

LinkLabel Control Display links to other resources Example 14.31: –URL: vb_htp_2010/codeexamples.htmlURL: vb_htp_2010/codeexamples.html cDriveLinkLabel.LinkClicked –cDriveLinkLabel.LinkVisited = True –Process.Start(“C:\”) –Process.Start(“ –Process.Start(“notepad”) 21

Process.Start(" ") Effect of Process.Start(" ") –Start  Run cmd calc notepad 22

ListBox and CheckedListBox Controls ListBox properties –MultiColumn –SelectedIndex -1 – no items are selected If multiple items are selected, one of selected indices is returned –SelectedIndices For multiple selected items –SelectedItem, SelectedItems –SelectionMode: None, One, MultiSimple, MultiExtended –Sorted: alphabetically, False by default 23

ListBox and CheckedListBox Controls (cont'd) ListBox methods –ClearSelected –GetSelected Take an index as an argument, and return True if the corresponding item is selected –myListBox.Items.Add(myListItem) ListBox Events –SelectedIndexChanged 24

ListBox and CheckedListBox Controls (cont'd) CheckedListBox properties –CheckedItems A collection of items that are checked –CheckedIndices A collection of indices for all checked items –CheckOnClick False by Default –SelectionMode Determine how many items can be checked: One or None 25

ListBox and CheckedListBox Controls (cont'd) CheckedListBox Method –GetItemChecked Take an index and returns True if the corresponding items is checked CheckedListBox Event –ItemCheck ItemCheckEventArgs –CurrentValue –Index –NewValue 26

Example 14.35: CheckedListBoxTest.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html itemCheckedListBox.SelectedItem.ToString() If e.NewValue = CheckState.Checked 27

Multiple Document Interface (MDI) Windows Single document interface (SDI) vs. multiple document interface (MDI) MDI: Parent and child windows 28 MDI parent MDI child

Multiple Document Interface (MDI) Windows (cont'd) Specify a form is an MDI container –Set IsMdiContainer property to True Create a class for child forms –Solution Explorer  Add  Windows Form… Create a new child form Set MdiParent property to the parent form Call the child form’s Show method 29

Multiple Document Interface (MDI) Windows (cont'd) MDI container features –MdiChildren property Return an array of child Form references –ActiveMdiChild property Return a reference to the active child window Tracking child windows in menus –MenuStrip class provides property MdiWindowListItem To check which child windows are open in an MDI container 30

Multiple Document Interface (MDI) Windows (cont'd) Arrange child windows –Parent form has method LayoutMdi Tiled windows (value TileHorizontal or TileVertical) Cascaded windows (value Cascade) 31

Example 14.42: UsingMDI.vb URL: – 10/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_htp_20 10/codeexamples.html Dim child = new ChildForm(“XXX”, “vb2008htp") –child.MdiParent = Me –child.Show() Me.LayoutMdi(MdiLayout.Cascade) Me.LayoutMdi(MdiLayout.TileHorizontal) Me.LayoutMdi(MdiLayout.TileVertical) 32

Animation with the Timer Component Timer component generates Tick events at fixed time interval –Timer component has Interval property The number of milliseconds between events –By default, timers are disabled Set Enabled property to True 33

Example 14.47: AnimationDemo.vb URL: – p_2010/codeexamples.htmlhttp://media.pearsoncmg.com/ph/esm/deitel/vb_ht p_2010/codeexamples.html Display a new image every 50 milliseconds –Handles animationTimer.Tick 34

35