Week 3: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook.

Slides:



Advertisements
Similar presentations
Pemrograman VisualMinggu …8… Page 1 MINGGU Ke Delapan Pemrograman Visual Pokok Bahasan: Graphical User Interface Tujuan Instruksional Khusus: Mahasiswa.
Advertisements

What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
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.
Dialog Boxes and Menus. Menus Menu Bar Contains menus which drop down to display list of menu items Each item has a name and text property Each item has.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
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.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
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)
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
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
BİL528 – Bilgisayar Programlama II Advanced Controls, Menus, Toolbars, and Status Bars 1.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
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 Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
CSCI 3327 Visual Basic Chapter 10: Windows Forms GUI: A Deeper Look UTPA – Fall 2011.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Week 2: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook.
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.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
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.
Graphical User Interface Concepts - Part 2 Session 09 Mata kuliah: M0874 – Programming II Tahun: 2010.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
© 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.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
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.
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.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
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 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Cách trộn thư trong Office 2003 Ứng dụng để làm giấy khen, giấy mời.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
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.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
Giáo viên: Nguyễn Ngọc Thúy Hằng Đơn vị: Trường THPT Lê Quý Đôn
Chapter 1: An Introduction to Visual Basic .NET
Graphical User Interface
Chapter 1: An Introduction to Visual Basic 2015
Week 3: WINDOWS PROGRAMMING
Chapter 1: An Introduction to Visual Basic 2015
GIÁO TRÌNH ĐÀO TẠO TRƯỜNG ĐẠI HỌC SÀI GÒN
Chương 8 KẾT NỐI VỚI SQL SERVER & ỨNG DỤNG TRÊN C#
Programming Based on Events
TÀI LIỆU GIẢNG DẠY IC3 GS4 SPARK
GIÁO TRÌNH ĐÀO TẠO TRƯỜNG ĐẠI HỌC SÀI GÒN
Creating a Windows Forms User Interface
Visual C# - GUI and controls - 1
Week 2: WINDOWS PROGRAMMING
Presentation transcript:

Week 3: WINDOWS PROGRAMMING Chapter 15 in “Beginning Visual C# 2010” ebook Chapter 4 in “”MCTS_Self-Paced_Training_Kit” ebook

4. GroupBoxes and Panels Arrange components on a GUI GroupBoxes can display a caption Text property determines its caption Panels can have scrollbar View additional controls inside the Panel Windows Programming 1 Chapter 15:Basic Windows Programming Slide 2 Group

GroupBox es and Panel s Windows Programming 1 Chapter 15:Basic Windows Programming Slide 3

GroupBox es and Panel s Windows Programming 1 Chapter 15:Basic Windows Programming Slide 4

GroupBox es and Panel s Fig Creating a Panel with scrollbars. Controls inside panel panel panel scrollbars Windows Programming 1 Chapter 15:Basic Windows Programming Slide 5

GroupBox es and Panel s Chapter 15:Basic Windows Programming

The FlowLayoutPanel Control The FlowLayoutPanel control is a subclass of the Panel control Unlike the Panel control, however, the FlowLayoutPanel dynamically repositions the controls it hosts when it is resized at either design time or run time Like the Panel control, the FlowLayoutPanel control is scrollable Windows Programming 1 Chapter 15:Basic Windows Programming Slide 7

The FlowLayoutPanel Control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 8

The SplitContainer Control The SplitContainer control creates a subsection of the form where Splitter divides SplitContainer into two SplitterPanel controls that function similarly to Panel controls. The SplitContainer.Dock property is set to Fill by default. SplitContainer exposes its two child SplitterPanel controls through its Panel1 and Panel2 properties Windows Programming 1 Chapter 15:Basic Windows Programming Slide 9

The SplitContainer Control PROPERTYDESCRIPTION BorderStyleRepresents the visual appearance of the TabPage border. It can be set to None, which indicates no border; FixedSingle, which creates a single-line border; or Fixed3D, which creates a border with a threedimensional appearance. IsSplitterFixedDetermines whether the location of Splitter is fixed and cannot be moved by the user OrientationDetermines whether Splitter is oriented horizontally or vertically in SplitContainer. It can be set to Horizontal or Vertical. Panel1Exposes the properties of the SplitContainer control’s Panel1. Panel2Exposes the properties of the SplitContainer control’s Panel2 Windows Programming 1 Chapter 15:Basic Windows Programming Slide 10

Dialog Boxes (dlg prefix) Predefined standard dialog boxes for: File Open and Saving Printing and Previewing Color selection Font selection Add the Common Dialog control to form Appears in the Component Tray, pane at bottom of Form Designer where nondisplay controls are shown Windows Programming 1 Chapter 15:Basic Windows Programming Slide 11

Drag common dialog to form Windows Programming 1 Chapter 15:Basic Windows Programming Slide 12

Common Dialog Controls OpenFileDialog SaveFileDialog FontDialog ColorDialog PrintDialog PrintPreviewDialog Windows Programming 1 Chapter 15:Basic Windows Programming Slide 13

FontDialog Windows Programming 1 Chapter 15:Basic Windows Programming Slide 14

FontDialog Property Font: Gets or sets the selected font. Property ShowEffects whether the dialog box contains controls that allow the user to specify strikethrough, underline,Color. Property Color: Gets or sets the selected font color Method Showdialog(): Windows Programming 1 Chapter 15:Basic Windows Programming Slide 15

ColorDialog Windows Programming 1 Chapter 15:Basic Windows Programming Slide 16

ColorDialog Property Color : get/set color select by the user Property FullOpen: True/false, whether the controls used to create custom colors are visible when the dialog box is opened Method Showdialog():Displays a dialog box user interface Windows Programming 1 Chapter 15:Basic Windows Programming Slide 17

ColorDialog colorDialog1.FullOpen=true; colorDialog1.Color = Color.Red; colorDialog1.ShowDialog(); lblDisplay.ForeColor = colorDialog1.Color; Windows Programming 1 Chapter 15:Basic Windows Programming Slide 18

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 19

OpenFileDialog - SaveFileDialog Property FileName: Gets or sets a string containing the file name selected in the file dialog box. Property Filter which determines the choices that appear in the "Save as file type" or "Files of type" box in the dialog box. Property FilterIndex: Gets or sets the index of the filter currently selected in the file dialog box. Property InitialDirectory: Gets or sets the initial directory displayed by the file dialog box. Property Title: Gets or sets the file dialog box title. Method Showdialog(): Windows Programming 1 Chapter 15:Basic Windows Programming Slide 20

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 21

The Button, CheckBox, and RadioButton Controls Button Text Click (event) CheckBox Checked CheckState ThreeState CheckedChanged (Event) RadioButton Checked CheckedChanged (Event) Windows Programming 1 Chapter 15:Basic Windows Programming Slide 22 Check box Radio

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 23

The ListBox Control The ListBox control is the simplest of the list- based controls and serves primarily to display a simple list of items in an easy-to-navigate user interface from which users can select one or more items Windows Programming 1 Chapter 15:Basic Windows Programming Slide 24

The ListBox and ComboBox Control ListBox tool lst prefix Simple List Box with/without scroll bars ComboBox tool cbo prefix List may allow for user to add new items List may "drop down" to display items in Windows Programming 1 Chapter 15:Basic Windows Programming Slide 25

The ListBox and ComboBox Control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 26 List Boxes Dropdown Combo Box Simple Combo Box Dropdown List Box

27 ListBox & ComboBox Danh sách item Cho phép thêm item trong màn hình thiết kế form

28 ListBox & ComboBox ListBox hiển thị dạng Multi Column Hiển thị nhiều cột

The ListBox Control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 29

Common ListBox Methods Windows Programming 1 Chapter 15:Basic Windows Programming Slide 30

The ListBox, CheckedListBox, and ComboBox Controls method a..Items.Add(“MyListItem”) lstMyListBox.Items.Add(“cat”); b..Items.RemoveAt(Index) lstMyListBox.Items.RemoveAt(3); c..Items.Remove(String) lstMyListbox.Item.Remove(“cat”); d..Items.Clear() lstMyListBox.Clear(); e..SetSelect(index, True/Fale) lstMyListBox.SetSelect(3,True); e..ClearSelect() Windows Programming 1 Chapter 15:Basic Windows Programming Slide 31

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 32

ComboBox Control The ComboBox control is similar to the ListBox control, but, in addition to allowing the user to select items from a list, it provides a space for a user to type an entry. Additionally, you can configure the ComboBox to either display a list of options or to provide a drop-down list of options Windows Programming 1 Chapter 15:Basic Windows Programming Slide 33

ComboBox Control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 34

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 35

The CheckedListBox Controls CheckedListBox displays a list of items to users and allows them to select multiple items by checking boxes that are displayed next to the items. Any number of items can be checked, but only one item can be selected at a time. You can retrieve a collection that represents the checked items by accessing the CheckedItems collection Windows Programming 1 Chapter 15:Basic Windows Programming Slide 36

The CheckedListBox Controls Windows Programming 1 Chapter 15:Basic Windows Programming Slide 37

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 38

The DomainUpDown and NumericUpDown Controls DomainUpDown (dud) Items ReadOnly SelectedIndex SelectedItem Sorted SelectedItemChanged (Event) Windows Programming 1 Chapter 15:Basic Windows Programming Slide 39

The DomainUpDown and NumericUpDown Controls NumericUpDown (nud) Increment Maximum Minimum Value ValueChanged Event Windows Programming 1 Chapter 15:Basic Windows Programming Slide 40

Demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 41

The MonthCalendar and DateTimePicker Controls Windows Programming 1 Chapter 15:Basic Windows Programming Slide 42

MonthCalendar properties and an event Windows Programming 1 Chapter 15:Basic Windows Programming Slide 43

DateTimePicker Control The DateTimePicker control enables the user to set a date, a time, or both in an easy- tounderstand graphical interface similar to a ComboBox control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 44

DateTimePicker properties and an event Windows Programming 1 Chapter 15:Basic Windows Programming Slide 45

The Timer, TrackBar, and ProgressBar Controls The Timer _ tmr Enabled Property Interval Property Start() Method Stop() Method Tick Event Windows Programming 1 Chapter 15:Basic Windows Programming Slide 46

47 Timer Properties Methods Enabled Interval Start Stop Tick

48 Timer Enable sự kiện Tick Khoảng thời gian chờ giữa 2 lần gọi Tick Hiển thị thời gian

49 Timer Sự kiện Tick Khai báo trình xử lý sự kiện Tick

50 Timer Demo Mỗi giây sự kiện Tick phát sinh. Trình xử lý của Tick sẽ lấy giờ hệ thống và hiển thị lên Label

The TrackBar Controls The TrackBar control provides a simple interface that enables the user to set a value from a predetermined range of values by graphically manipulating a slider with the mouse or keyboard commands. This enables the user to rapidly set a value from a potentially very large range. Windows Programming 1 Chapter 15:Basic Windows Programming Slide 51

The TrackBar Controls Windows Programming 1 Chapter 15:Basic Windows Programming Slide 52

The Timer, TrackBar, and ProgressBar Controls ProgressBar (prg) Maximum Property(100) Minimum Property(0) Value Property(0) Windows Programming 1 Chapter 15:Basic Windows Programming Slide 53

The TabControl The TabControl control enables you to group sets of controls in tabs, rather like files in a filing cabinet or dividers in a notebook. TabControl serves as a host for one or more TabPage controls, which themselves contain controls. The user can switch between tab pages (and the controls contained therein) by clicking the tabs on TabControl Windows Programming 1 Chapter 15:Basic Windows Programming Slide 54

The TabControl Windows Programming 1 Chapter 15:Basic Windows Programming Slide 55

ToolTips We demonstrated tool tipsthe helpful text that appears when the mouse hovers over an item in a GUI Windows Programming 1 Chapter 15:Basic Windows Programming Slide 56

Menus (mnu prefix) Menus provide groups of related commands for Windows applications separator bars Checked menu item Windows Programming 1 Chapter 15:Basic Windows Programming Slide 57

Menu Design Standards Windows Programming 1 Chapter 15:Basic Windows Programming Slide 58 New(Ctrl N) Open(Ctrl O) Close Save As Save (Ctrl S) Print(Ctrl P) Exit Undo(Ctrl Z) Cut(Ctrl X) Copy(Ctrl C) Paste(Ctrl V) Find(Ctrl F) Replace(Ctrl H) File MenuEdit Menu

The MenuStrip Control The MenuStrip control is essentially a ToolStrip control optimized for the display of ToolStripMenu items. The MenuStrip control derives from ToolStrip and can host all the tool strip items described in the previous lesson. Its primary function, however, is to host ToolStripMenu items. ToolStripMenuItem controls are the controls that provide the visual representation for items on a menu. They can appear as text, an image, or both and can execute code found in their ToolStripMenuItem Windows Programming 1 Chapter 15:Basic Windows Programming Slide 59

The MenuStrip Control Windows Programming 1 Chapter 15:Basic Windows Programming Slide 60

ToolStripMenuItem properties Windows Programming 1 Chapter 15:Basic Windows Programming Slide 61

CREATING MENUS AND MENU ITEMS To create an access shortcut (or keyboard shortcut), Windows Programming 1 Chapter 15:Basic Windows Programming Slide 62

CREATING MENUS AND MENU ITEMS To create an access shortcut (or keyboard shortcut), Windows Programming 1 Chapter 15:Basic Windows Programming Slide 63

CREATING MENUS AND MENU ITEMS To add other shortcut keys (e.g., -F9) Windows Programming 1 Chapter 15:Basic Windows Programming Slide 64

Adding Separator Bars to Menus You can add a separator to any submenu at design time by choosing Separator from the drop-down box in the menu item design interface. Using “-” Windows Programming 1 Chapter 15:Basic Windows Programming Slide 65

MenuStrip and ToolStripMenuItem an event. ClickGenerated when an item is clicked or a shortcut key is used. This is the default event when the menu is double clicked in the designer DropDownOpenedOccurs when Dropdown hasoOpened Windows Programming 1 Slide 66

Context Menus and the ContextMenuStrip Control All controls that can display a context menu expose a ContextMenuStrip property that represents the context menu associated with that control A context menu is invoked when the user right-clicks a control. You can set this property at design time in the Properties window. Windows Programming 1 Chapter 15:Basic Windows Programming Slide 67

68 Context Menu Demo: tạo context Menu hiển thị trong ListBox có menu item Remove, cho phép xóa item đang được chọn. Tạo Form có mô tả như sau ListBox hiển thị các item

69 Context Menu Kéo ContextMenuStrip thả vào Form

70 Context Menu Kích vào ContextMenuStrip để thiết kế menu Tạo một menu item “Remove” như hình mô tả Soạn thảo các menu item

71 Context Menu Liên kết ContextMenu với ListBox Trong cửa sổ properties của ListBox Khai báo thuộc tính ContextMenuStrip = ContextMenuStrip1 Chọn context menu

72 Context Menu Khai báo trình xử lý sự kiện Click cho menu item

73 Context Menu Demo Context Menu hiển thị khi user kích chuột phải lên ListBox

The StatusBar Control Alignment Property AutoSize Property BorderStyle Property Icon Property Style Property ToolTipText Property Windows Programming 1 Chapter 15:Basic Windows Programming Slide 74

The ToolBar Control Buttons Property ButtonClick Event ImageList Property SendToBack() Method ShowToolTips Property Windows Programming 1 Chapter 15:Basic Windows Programming Slide 75

CREATING MDI APPLICATIONS Multiple Document Interface (MDI) Windows Single Document Interface (SDI)Multiple Document Interface (MDI) Windows Programming 1 Chapter 15:Basic Windows Programming Slide 76

CREATING MDI APPLICATIONS ActiveMdiChild Property IsMdiContainer Property MdiChildActivate Event MdiChildren Property MdiParent Property LayoutMdi() Method Windows Programming 1 Chapter 15:Basic Windows Programming Slide 77

Multiple Document Interface (MDI) Windows ArrangeIcons Cascade LayoutMdi( MdiLayout.ArrangeIcons); LayoutMdi( MdiLayout.Cascade); Windows Programming 1 Chapter 15:Basic Windows Programming Slide 78

Multiple Document Interface (MDI) Windows TileHorizontal TileVertical LayoutMdi(MdiLayout.TileHorizontal);LayoutMdi(MdiLayout.TileVertical); Windows Programming 1 Chapter 15:Basic Windows Programming Slide 79

Form Splash Windows Programming 1 Chapter 15:Basic Windows Programming Slide 80

Form Splash FormBorderStyle=None; StartPosition = CenterToScreen; TopMost = true; Windows Programming 1 Chapter 15:Basic Windows Programming Slide 81

Form Splash static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); frmFlashForm f = new frmFlashForm(); f.ShowDialog(); if (f.DialogResult == DialogResult.OK) { Application.Run(new frmFormMain()); } } Windows Programming 1 Chapter 15:Basic Windows Programming Slide 82

Form Splash private void timer1_Tick(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; timer1.Enabled = false; } Windows Programming 1 Chapter 15:Basic Windows Programming Slide 83

Form About Windows Programming 1 Chapter 15:Basic Windows Programming Slide 84

Mouse-Event Handling Mouse events can be handled for any control that derives from class System.Windows.Forms.Control MouseEventArgs (object as arguments ) MouseEventHandler (requires an object ) Class MouseEventArgs contains information related to the mouse event, such as the mouse pointer's x- and y-coordinates, the mouse button pressed (Right, Left or Middle) and the number of times the mouse was clicked Windows Programming 1 Chapter 15:Basic Windows Programming Slide 85

86 Mouse Event Tọa độ (x,y) của con trỏ chuột Button được nhấn Số lần kích chuột MouseEventArgs

Mouse events and event arguments Windows Programming 1 Chapter 15:Basic Windows Programming Slide 87

88 Sự kiện chuột với tham số kiểu EventArgs MouseEnterOccurs when mouse enters the visible part of control MouseLeaveXuất hiện khi con trỏ chuột rời khỏi biên của control Sự kiện chuột với tham số kiểu MouseEventArgs MouseDown/ MouseUp Xuất hiện khi button được nhấn/thả và con trỏ chuột đang ở trong vùng biên của control MouseMoveXuất hiện khi chuột di chuyển và con trỏ chuột ở trong vùng biên của control Mouse Event

89 Mouse Event MouseMove

90 Mouse Event - Mousemove Demo Hiển thị tọa độ hiện tại của con trỏ chuột Vị trí hiện tại của con trỏ chuột

91 Mouse Event Demo thao tác: kích chuột trái tại một điểm A, giữ chuột trái và di chuyển chuột, chương trình sẽ vẽ đường thẳng từ điểm A đến vị trí hiện tại chuột. Các sự kiện cần xử lý MouseDown: Xác định điểm A ban đầu MouseMove Kiểm tra nếu Left button của chuột đang giữ  Sử dụng Graphics để vẽ đường thẳng từ A đến vị trí hiện tại

92 Mouse Event Bước 1: Tạo biến lưu trữ điểm A khi user kích chuột trái Biến pA có kiểu Point là biến thành viên của Form1 Lớp Form1 Biến pA lưu giữ tọa độ khi chuột trái được click

93 Mouse Event Bước 2 Khai báo xử lý sự kiện MouseDown trong Form1 Trong cửa sổ event của Form1, kích đúp vào sự kiện MouseDown Lưu lại điểm được nhấn chuột

94 Mouse Event Bước 3 Cài đặt xử lý sự kiện MouseMove Kiểm tra nếu LeftButton được nhấn  Vẽ đường thẳng từ pA đến vị trí hiện tại

demo Windows Programming 1 Chapter 15:Basic Windows Programming Slide 95

Keyboard - Event Handling Key events occur when keyboard keys are pressed and released. Such events can be handled for any control that inherits from System.Windows.Forms.Control There are three key events KeyPress, KeyUp and KeyDown Windows Programming 1 Chapter 15:Basic Windows Programming Slide 96

Keyboard - Event Handling The KeyPress event occurs when the user presses a key that represents an ASCII character The specific key can be determined with property KeyChar of the event handler's KeyPressEventArgs argument The KeyPress event does not indicate whether modifier keys (e.g., Shift, Alt and Ctrl) were pressed when a key event occurred If this information is important, the KeyUp or KeyDown events can be used The KeyEventArgs argument for each of these events contains information about modifier keys Windows Programming 1 Chapter 15:Basic Windows Programming Slide 97

Keyboard events and event arguments Windows Programming 1 Chapter 15:Basic Windows Programming Slide 98

Windows Programming 1 Chapter 15:Basic Windows Programming Slide 99

Windows Programming 1 Chapter 15:Basic Windows Programming Slide 100

Finish Windows Programming 1 Chapter 15:Basic Windows Programming Slide 101