Unformatted text preview:

Chapter 2 More Controls (Con’t)ReviewForms (frm)Text Boxes (txt)Buttons (btn) / Labels (lbl)Check Boxes (chk)/Radio Buttons (rad)FocusThe Tab OrderThe Tab Order cont.Setting the Tab OrderSetting the Form’s Location on the ScreenCreating ToolTipsBefore adding Tool TipAfter Adding Tool TipResultCoding for the ControlsClearing Text Boxes and LabelsResetting the FocusSet the Checked Property of Radio Buttons and Check BoxesSetting Visibility at Run TimeChanging the Color of TextConcatenating TextContinuing Long Program LinesWriting Event HandlersGood Programming HabitsGood Programming Habits cont.Your Hands-On Programming ExampleChapter 3 Variables, Constants, and CalculationsData – Variables and ConstantsData – Variables and Constants cont.Data TypesC# Data TypesIdentifier Naming RulesIdentifier Naming ConventionsCommon Data Types and PrefixesConstants – Named and IntrinsicNamed ConstantsNamed Constants cont.Assigning Values to ConstantsAssigning Values to Constants cont.Slide 41Intrinsic ConstantsDeclaring VariablesDeclaring Variables cont.Initializing Numeric VariablesScope and Lifetime of VariablesScope and Lifetime of Variables cont.Local DeclarationsClass-Level DeclarationsLocations for Coding Variables and ConstantsCoding Class, Block, and Namespace-Level DeclarationsCalculationsConverting Strings to a Numeric Data TypeArithmetic OperationsArithmetic OperatorsOrder of OperationsUsing Calculations in CodeIncrement and Decrement OperatorsConverting between Numeric Data TypesCalculations with Unlike Data TypesRounding NumbersFormatting Data for DisplayUsing Format Specifier CodesUsing Format Specifier Codes cont.Format Specifier CodesHandling Exceptionstry / catch BlocksThe try Block – General FormThe Exception ClassHandling Multiple ExceptionsDisplaying Messages in Message BoxesDisplaying Messages in Message Boxes cont.Slide 73MessageBox Statement ExamplesUsing Overloaded MethodsTesting Multiple FieldsCounting and Accumulating SumsPowerPoint PresentationChapter 2More Controls (Con’t)Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2ReviewPropertiesMethodsEventsIDEForm DesignerTool BoxSolution ExplorerNaming StandardsPropertiesNameText – Access KeysVisibleAnchorMethodsFocus()3Forms (frm)PropertiesFontAcceptButtonCancelButtonStartPositionTabStop - trueEventsLoadActivatedMethodsClose()Show()Hide()4Text Boxes (txt)EventsTextAlignWordWrapText PasswordCharEventsEnterLeaveTextChangedMethodsClear()SelectAll()5Buttons (btn) / Labels (lbl)ButtonsTabStop - trueEventsClickLabelsUsed for titles and messagesSetting Access key cause control next in the tab order to get Focus6Check Boxes (chk)/Radio Buttons (rad)Check BoxesAllows multiple selectionsPropertiesCheckedTabStop - trueEventsCheckedChangedRadio Buttons Mutually exclusivePut in a Group BoxPropertiesCheckedTabStop - falseEventsCheckedChanged7Focus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 cannot8The Tab OrderControls that can receive focus have a TabStop propertyDetermines if tab key will stop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 TabIndex9The 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If set to trueTab key takes you to one radio button in a group; Arrow keys to move to another radio button in the group10Setting 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 numbers11Setting 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CenterParent12Creating 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)13Before adding Tool Tip14After Adding Tool Tip15Result16Coding 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 changing the color of text17Clearing 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: txtName.Text = “”;lbl.Message.Text = “”;txtDataEntryBox.Clear();txtMessage.Text = string.Empty;18Resetting the FocusUse the Focus method to reset the focus to a particular controlExample: txtName.Focus();19Set 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:radRed.Checked = true; //Select buttonchkDisplay.Checked = true; //Make box checkedchkDisplay.Checked = false; //Make box uncheckedchkBox.Checked = ! chkBox.Checked ; // Set to opposite20Setting Visibility at Run TimeUse Visible property to set visibilityExample: lblMessage.Visible = false;Can make visibility depend on selection user makes in a check box or radio buttonExample: lblMessage.Visible = chkDisplay.Checked;21Changing 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: txtName.ForeColor = Color.Red;


View Full Document

St. Ambrose CSCI 480 - LECTURE NOTES

Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?