Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.

Slides:



Advertisements
Similar presentations
Chapter 3 Creating a Business Letter with a Letterhead and Table
Advertisements

Chapter 1: An Introduction to Visual Basic 2012
Chapter 3.1 Controls Programming In Visual Basic.NET.
Chapter 2 More Controls Programming In Visual Basic.NET.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
© by Pearson Education, Inc. All Rights Reserved. continued …
1.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Introducing More Controls Text boxCheck box Option button Command button frame image.
Chapter 2 More Controls Programming In Visual Basic.NET.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Chapter 2 User Interface Design Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
110-C1 Chapter 2 of the text: _ text boxes, group boxes, check boxes, radio buttons, picture boxes _ defining access keys tab sequence setting the focus.
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)
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
Chapter 2 User Interface Design Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
IE 411/511: Visual Programming for Industrial Applications
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
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.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
User Interface Design. Text Boxes Use a text box control when you want the user to type some input.
Graphical User Interfaces 2 Tonga Institute of Higher Education.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Visual Basic.NET BASICS Lesson 3 Events and Code.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
2-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Chapter 2 P. 1 Introducing more controls (on the Toolbox) (Fig. 2.1) - Text box - Frame - Option button - Check box - Image Example P. 44 Figure 2.2 Message.
Chapter 2 – Introduction to the Visual Studio .NET IDE
More Controls and Their Properties Part 4 dbg --- TextBox, CheckBox, RadioButton, GroupBox, ToolTips,
More User Interface Controls User interface controls are located in the toolbox. Click the +/- signs to open/ close the different tabs of the tollbox.
McGraw-Hill © 2010 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 2 User Interface Design.
2-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 2 User Interface Design.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Microsoft Visual Basic 2005 BASICS Lesson 3 Events and Code.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al- ajmi Chapter 3 Some Visual Basic Controls and Events 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.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
MsgBox, Input Box Functions Check boxes, radio button MsgBox, Input Box Functions Lab 3 3 Ismail M. Romi: PPU- IT Dept.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Chapter 2 More Controls Programming In C Shap. © Controls in the Toolbox.
 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.
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
How to design a Windows Forms application
Visual programming Chapter 3: GUI (Graphical User Interface) Part I
Variables and Arithmetic Operations
Brief description on how to navigate within this presentation (ppt)
Programming In Visual Basic.NET
Chapter 2 User Interface Design
Welcome To Microsoft Word 2016
Presentation transcript:

Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.

2- 2 Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively Set the BorderStyle property to make controls appear flat or three-dimensional Select multiple controls and move them, align them, and set common properties

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Objectives cont. Make your projects easy for the user to understand and operate Clear the contents of text boxes and labels Change text color during program execution Concatenate (join) strings of text Make a control visible or invisible at run time by setting its Visible property

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Introducing More Controls Text boxes, group boxes, check boxes, radio buttons, and picture boxes are found in the toolbox Each class of controls has own properties To see control properties –Place control on form and view properties list or –Click on control and press F1 for Help

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Text Boxes Use a text box when you want the user to type some input Set the Text property in code to assign a literal for display Set the TextAlign property to change alignment of text in the box –HorizontalAlignment.Left –HorizontalAlignment.Right –HorizontalAlignment.Center Example: messageText.TextAlign=HorizontalAlignment.Left;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Group Boxes Used as containers for other controls Make forms easier to understand Set Text property to words to appear on top edge of group box

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Check Boxes Allow user to select or deselect an option In a group of check boxes, any number may be selected The Checked property is set to true if checked and false if not checked CheckedChanged event triggers when the user clicks in a Check Box Text property sets text to appear next to the box

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Radio Buttons Use when only one button of a group may be selected Radio buttons placed directly on a form function as a group The Checked property is set to true if checked and false if not checked CheckedChanged event triggers when the user clicks on a Radio Button

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Picture Boxes Used to hold an image Set Image property to the name of a graphic file The picture is saved in the form’s.resx file Set the SizeMode property to StretchImage to make picture fill the control

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting a Border and Style Labels, text boxes, and picture boxes have a BorderStyle property BorderStyle options –None –FixedSingle –Fixed3D

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Drawing a Line Draw a line using the Label control –Set Text property to blank –Set BorderStyle to None –Change Backcolor to color of line –Control size of line using Width and Height properties

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Selecting Multiple Controls Drag a selection box around the controls Click on one control to select it; Hold down the Ctrl or Shift key and click on other controls to select Use combination of above methods Click Select All on the Edit menu to select all controls on a form Click anywhere on form or on another control to deselect the controls

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Controls as a Group Move controls as a group by clicking on one of the selected controls and dragging the group to a new location Set common properties for group of controls using the Properties window Align group of controls using buttons on the Layout toolbar or items on the Format menu

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Designing the User Interface Design applications to match other Windows applications Follow industry standards for color, size, and placement of controls –Windows applications are mostly gray –Color can indicate what is expected of the user –Group controls to aid the user –Use sans serif font on forms and do not make them bold –Limit large font sizes to a few items

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Defining Keyboard Access Keys Use access keys (hot keys) for project response with keyboard Type an ampersand (&) in front of the character to be the access character Example: &OK for OK Use Windows-standard keys whenever possible Make sure you don’t give two controls the same access key

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting the Accept and Cancel Buttons It is sometimes preferable to use the Enter key or Esc key instead of moving the mouse Accept button acts as the Enter key –Set the AcceptButton property of form to button name Cancel button acts as the Esc key –Set the CancelButton property of form to button name

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Focus One control on the form always has the focus Focus may appear as a light dotted line on some controls such as buttons Insertion point appears inside a text box that has focus Some controls can receive focus and others cannot

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved The Tab Order Controls that can receive focus have a TabStop property The TabIndex property determines the order the focus moves as the Tab key is pressed As controls are created, TabIndex is set in sequence When program starts, focus is on the control with lowest TabIndex

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved The Tab Order cont. Label controls cannot receive focus Default value of TabStop for buttons and text boxes is true Default value of TabStop for radio buttons is false The tab key takes you to one radio button in a group; Use arrow keys to move to another radio button in the group

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting the Tab Order Set each control’s TabIndex property in Properties window Can also use Visual Studio.NET feature to set TabIndexes automatically –Open Design window –Select View / Tab Order –Click on controls in desired tab order –Sequence numbers representing tab order on controls are updated –Select View / Tab Order to hide sequence numbers

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting the Form’s Location on the Screen By default, the form appears in the upper-left corner of the screen Set form’s screen position with StartPosition property StartPosition options –Manual –CenterScreen –WindowsDefaultLocation –WindowsDefaultBounds –CenterParent

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating ToolTips Add a ToolTip component to a form ToolTip control is placed in component tray at bottom of the Form Designer Component tray hold controls that do not have a visual representation at run time Each control on form has new property: ToolTip on ToolTip1 (assume name of control is ToolTip1)

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Coding for the Controls You can change properties as a project executes Examples include clearing out contents of a text box or label, resetting the focus, and changing the color of text

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Clearing Text Boxes and Labels Set Text property to an empty string Empty string shown as “” Use the Clear() method Set the Text property to string.Empty Examples: nameTextBox.Text = “”; messageLabel.Text = “”; dataEntryTextBox.Clear(); messageLabel.Text = string.Empty;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Resetting the Focus Use the Focus method to reset the focus to a particular control Example: nameTextBox.Focus();

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Set the Checked Property of Radio Buttons and Check Boxes Select or deselect a control in code by setting the Checked property to true or false Must use lowercase for true or false Examples: redRadioButton.Checked = true; //Select button displayCheckBox.Checked = true; //Make box checked displayCheckBox.Checked = false; //Make box unchecked

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting Visibility at Run Time Use Visible property to set visibility Example: messageLabel.Visible = false ; Can make visibility depend on selection user makes in a check box or radio button Example: messageLabel.Visible = displayCheckBox.Checked;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Changing the Color of Text Use ForeColor property to change the color of the text Use BackColor property to change the color around the text The Color class contains color constants Type keyword Color and a period to see full list of available colors Examples: nameTextBox.ForeColor = Color.Red; messageLabel.ForeColor = Color.White;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Concatenating Text Join two strings of text using process called concatenation Use a plus (+) between the two strings Example: messageLabel.Text = “Your name is “ + nameTextBox.Text;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Continuing Long Program Lines You can break a statement at any white space The end of a statement is determined by the semicolon To break in the middle of a literal, you must concatenate the strings to rejoin them Example: greetingsLabel.Text = “Greetings “ + nameTextBox.Text + “: You have been selected to win a free prize. “ + “Just send us $100 for postage and handling”;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Writing Event Handlers Select the method to respond to an event in the Properties window –Click on Events button at top of window –Select the event and drop down list of available methods

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Your Hands-On Programming Example For this example you will write a program that uses many of the new controls and topics introduced in this chapter. The program will input the user’s name and a message and display the two items concatenated in a label. The user can change the color of the label’s text by selecting with radio buttons, and hide or display the output by checking a check box.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Your Hands-On Programming Example cont. You will include buttons to display the message in the label, clear the text boxes and label, and exit. Include the keyboard access keys; make the Display button the accept button and make the Clear button the cancel button. Place a logo on the form. Actually, you will place two picture boxes with different sizes for the logo on the form. Each time the user clicks on the logo, it will toggle the large and small versions of the logo. Add a ToolTip to the logo that says “Click here”.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Good Programming Habits Make the text in a text box right justified or centered using the TextAlign property Use the Checked property of a check box to set other properties that must be true or false Always test the tab order on your forms; Fix it if necessary using the TabIndex properties

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Good Programming Habits cont. Create multiple controls of the same type by Ctrl-clicking on the tool and drawing the needed controls Use text boxes when you want the user to enter or change the text Use label controls when you do not want the user to change data

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary Text boxes are used primarily for user input. Group boxes are used as containers for other controls and to group like items on a form. Check boxes and radio buttons allow the user to make choices. The current state of check boxes and radio buttons is stored in the Checked property. Picture box controls hold a graphic which is assigned to the Image property.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary cont. The BorderStyle property determines whether the control appears flat or three-dimensional. Use a Label control to create a line on a form. You can select multiple controls and treat them as a group. Follow Windows standard guidelines for colors, control size and placement, access keys, default and cancel buttons, and tab order.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary cont. Define keyboard access keys by including an ampersand in the Text property. Set the AcceptButton property so the user can press Enter, and set the CancelButton property so the user can press Esc. The focus moves from control to control as the user presses the Tab key. Add a ToolTip control to a form then set the ToolTip on ToolTip1 property for each control.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary cont. Clear the Text property by setting it to an empty string. Use the Focus method to make a control have focus. You can set the Checked property of a radio button or checkbox at run time, and the Visible property of all controls. Change the color of text in a control with the ForeColor property. Use the color constants to change colors at run time. Concatenation is the joining of two strings with a plus sign.