CIS 115 Lecture 3.  Forms  Form properties  Controls  Control properties  Event Driven Programming  Form Events  Control Events  Event Handlers.

Slides:



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

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
Chapter 1: An Introduction to Visual Basic 2012
Chapter 3.1 Controls Programming In Visual Basic.NET.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter 2 –Visual Basic, Controls, and Events
Chapter Creating Applications With Visual Basic 2.
Chapter Creating Applications With Visual Basic 2.
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.
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Chapter 2 –Visual Basic, Controls, and Events
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 1: Chapter 2: Slide 1 Unit 1 Introduction to Programming Using VB.NET Chapter.
Visual Basic Chapter 1 Mr. Wangler.
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
ASP.NET Web Server Controls Basic Web Server Controls.
Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 2 Creating Applications With Visual Basic.NET.
Introduction to Visual Basic.NET Chapter 2 Introduction to Controls, Events.
CIS 338: VB.NET Components Dr. Ralph D. Westfall April, 2011.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
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.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
Chapter 2 –Visual Basic, Controls, and Events
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
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.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
VB Objects & Events (Exercises) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 3, Friday 1/31/2003)
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Chapter 31 Fundamentals of Programming in Visual Basic (VB) Visual Basic Events Simple Statement.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
CIS 338: Events Dr. Ralph D. Westfall April, 2011.
Chapter 31 Fundamentals of Programming in Visual Basic (VB) Visual Basic Events Simple Statement.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
Chapter 2 - VB 2008 by Schneider1 Chapter 2 –Visual Basic, Controls, and Events 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual.
Dr. Abraham Professor UTPA Graphical User Interface.
COMPUTER PROGRAMMING I Apply Procedures to Develop List Box and Combo Box Objects.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
Graphical User Interface Concepts - Part 1 Session 08 Mata kuliah: M0874 – Programming II Tahun: 2010.
ALMAJMA'AH UNIVERSITY College of Science and Humanitarians Studies in Alghat Information Technology Section (211Tal course) 1.
Chapter 1: An Introduction to Visual Basic .NET
Visual Basic.NET Windows Programming
Chapter 1: An Introduction to Visual Basic 2015
ITE 370: VB.NET Solution Overview ITE 370
Building an Application in the Visual Basic .NET Environment
Project Design, Forms and Buttons
Visual C# - GUI and controls - 1
STARTING OUT WITH Visual Basic 2008
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

CIS 115 Lecture 3

 Forms  Form properties  Controls  Control properties  Event Driven Programming  Form Events  Control Events  Event Handlers  VB Example Program

 A form is a container for controls  A form is used to design a GUI-based window in a Windows application  A form displays information and receives input from the user.  Always orient a form at a task as defined by the user

 Text – defines the text to display in the caption bar  StartPosition – determines position of form when it first appears (eg. CenterScreen)  Size.Width, Size.Height – the 2D area occupied by the form, in units of pixels  Location.X, Location.Y – the relative position of the form on the screen  Visible – can be seen by the user  Enabled – the user can interact with the form

 FormBorderStyle – determines the appearance and behavior of the borders of the form  Sizable: (Default) Has min, max, and close buttons; can be resized by dragging edges  Fixed3D: Has a 3D look; min, max, and close buttons; cannot be resized  FixedSingle: Has single line border; min, max, and close buttons; cannot be resized  AcceptButton - designates which button on the form is activated by the Enter Key  Cancel Button - designates which button on the form is activated by the ESC Key

 Visual objects that are placed on a form to enable customized activities  Familiar Visual Basic controls:  Label - displays text the user cannot change  TextBox - allows the user to enter text  Button – performs an action when clicked  RadioButton - A round button that is selected or deselected with a mouse  CheckBox – A box that is checked or unchecked with a mouse click  Form - A window that contains these controls  Built-in controls defined in Windows Form class library, and are defined  with ToolBox and Form Designer  or strictly with code

 Text edit (TextBox—txt___)  Text display (Label—default name or lbl___)  Selection from a list (ListBox—lst___, ComboBox—cbo___, ListView, TreeView, NumericUpDown…)  Graphic display (PictureBox—pic___)  Graphic storage (ImageList)  Value setting (CheckBox—chk___, CheckListBox, RadioButton,…)  Date setting (DateTimePicker, MonthCalendar)  Dialog boxes (OpenFileDialog, PrintDialog…)  Menu controls (MainMenu, …)  Commands (Button—btn___, LinkLabel…)  Grouping other controls (GroupBox, TabControl, Panel)

 Common properties shared by many controls  Name, Text  Size.Height & Width, Location.X &Y, Dock  BackColor: Sets the background (fill) color  ForeColor: Sets the foreground (text) color  CanFocus, ContainsFocus, Focused  Visible & Enabled determine availability to user  Font properties affect text display in the control ▪ Font, size, bold, etc.  Tab Index & Tab Stop

 Design Time  Set in Properties Window  Run Time  Set / Change in Code

Slide  Specify the control name (btnExit)  Then a dot  Then the PropertyName (Visible)  controlName.propertyName  btnExit.Visible ▪ refers to the Visible property of the btnExit control ▪ The visible property values may only be true or false

 Item to receive the value (Left Side)  Assignment Indicator =  Value to be assigned(Right Side)  VariableName = Value  NumberVariable = 5  ControlName.PropertyName = Setting  btnExit.Visible = False ▪ Assigns the value False to the Visible property of the btnExit control ▪ Causes the text of the btnExit control to become hidden to the user  txtFirstName.text = “Paul”  txtLastName.text = “Overstreet”

 Properties  Text ▪ &Cancel -> Cancel ▪ && -> &  Events  Click

 Use labels and link labels for text display  Text property (no more Caption) defines text to display  User cannot change a label  LinkLabel enables hyperlinks  Links.Add inserts a hyperlink into text  Must write event-handler to invoke browser  See example

 Text box allows user to enter or edit data  Properties  MaxLength, MultiLine  AcceptsTab  AcceptsReturn  WordWrap  ScrollBars  Events  TextChanged

 CheckState property  Checked  Unchecked  Indeterminate (checked but grayed)  Text property displays built-in caption If chkMarried.CheckState = CheckState.Checked Then  End If

 ComboBox Properties  Text  DropDownStyle ▪ Simple ▪ Dropdown ▪ DropdownList  Sorted  Methods  Items.Clear  Items.Add  Items.Remove cboChoice.Items.Clear() cboChoice.Items.Add("First") cboChoice.Items.Add("Second") cboChoice.Items.Add("Third") cboChoice.Items.Add(TextBox1.Text) cboChoice.Items.Remove("Third")

 Executes code after a specified interval  Timer Event  Unique event that executes after the interval specified in the interval property expires  Interval Property  ,535 milliseconds ▪ 0 - means disabled ▪ 60,000 milliseconds is one minute  Enabled property must also be true for timer to work.  Timer control is never visible at run time  Stored in Component Tray at design time

 Applications recognize and respond to events by executing code known as event procedures  Event: An action that is recognized by an object.  User Actions ▪ Mouse Click ▪ Entering Text ▪ Pressing a Key  Program Calculations  Triggered by the system ▪ Timer  Event Handler: Code that is written by the programmer to respond to an event  Executes only when particular event occurs

 Common Form Events  Form1_Load() - Occurs before a form is displayed for the first time.  Form1_Activated() - Occurs when form becomes the active window - through code or by user  Form1_Deactivate() - Occurs when the form loses focus and is not the active form  Form1_Closing() - Occurs when the form closes, either through an event or the windows close button being clicked

 Many controls share a Common set of events to which they can react  Click, DoubleClick  MouseMove, MouseDown, MouseUp, MouseWheel, MouseHover, MouseLeave  KeyPress, KeyDown, KeyUp  Resize  DragDrop  GotFocus  LostFocus

 Focus is when an object becomes the “Active Control”  Focus Event Sequence:  Enter  GotFocus  Leave  Validating  Validated  LostFocus

 Create Event Procedure  Double Click on Control  Displays Code Window and Event Procedure Stub for default event Or  Open the Code Editor (F7 or View Menu:Code Command)  Select Control & Event from drop down windows in Code Editor Event Code Goes In Here

Exit Button – Clicked Method (btnExit_Click) Private Sub btnExit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnExit.Click ' End the application End End Sub Line Continuation Mark Name of the event the procedure responds to Name of the control that owns the event procedure Marks the beginning of this event procedure Ends the program Event handled by this procedure

 Input  Controls  Process  Events  Output  Controls

UDIE – Implement the solution in VB:  Create the Interface  Input Controls  Output Controls  Set the Properties  Configure the appearance and behavior of the controls  Write the Code to execute when events occur  Process the inputs to create the outputs

 Using Visual Basic.Net create the following formObjectPropertySettingForm1TextDemonstration txtFirstText(blank) txtSecondText(blank) btnRedText Change Color to Red

When btnRed is clicked - Change txtFirst text color to red  Double Click on btnRed  Code window should appear (with Event Procedure Stub)  Add code to the event procedure stub: txtFirst.ForeColor = Color.Red

When the text is edited in txtFirst - Change txtFirst text color to blue  In Code Window  Select the Control for the Event Procedure  txtFirst from the ClassName box  Select the Event from the Method Name Box  TextChanged Class Name Box Method Name Box

 Add code to the event procedure stub:  txtFirst.ForeColor = Color.Blue

When txtFirst is deselected - Change txtFirst text color to black  In Code Window  Select the Control for the Event Procedure  txtFirst from the ClassName box  Select the Event from the Method Name Box  Leave  Add code to the event procedure stub:  txtFirst.ForeColor = Color.Black

 Click F5 or the Run Button  Type “Hello” into the 1st textbox  What Happens  Click on the 2 nd Textbox  What happened in txtFirst and Why  Click on the Button  What happened in txtFirst  Type “Friends” into the 1 st textbox  Stop Program by clicking Red X in corner

 Add a Button to your Form  Name: btnExit  Text Property: &Quit  Add a Button Click Event for this Button  Code: END

 Finds Syntax Errors (Errors in Programming Language)  Return to btnRed Click Event Procedure  Add this line of Code:  txtSecond.text = Hello Notice Wavy Blue Line – This indicates a Syntax Error that must be fixed.

 Test All Events  Click Quit Button

 Homework 1  Visual Basic Controls and Properties  See handout for details and due date  Questions?