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.2ReviewPropertiesMethodsEventsIDEForm DesignerTool BoxSolution ExplorerNaming StandardsPropertiesNameText – Access KeysVisibleAnchorMethodsFocus()3Forms (frm)PropertiesFontAcceptButtonCancelButtonStartPositionTabStop - trueEventsLoadActivatedMethodsClose()Show()Hide()4Text Boxes (txt)EventsTextAlignWordWrapText PasswordCharEventsEnterLeaveTextChangedMethodsClear()SelectAll()5Buttons (btn) / Labels (lbl)ButtonsTabStop - trueEventsClickLabelsUsed for titles and messagesSetting Access key cause control next in the tab order to get Focus6Check Boxes (chk)/Radio Buttons (rad)Check BoxesAllows multiple selectionsPropertiesCheckedTabStop - trueEventsCheckedChangedRadio Buttons Mutually exclusivePut in a Group BoxPropertiesCheckedTabStop - falseEventsCheckedChanged7FocusOne control on the form always has the focusFocus may appear as a light dotted line on some controls such as buttonsInsertion point appears inside a text box that has focusSome controls can receive focus and others cannot8The Tab OrderControls that can receive focus have a TabStop propertyDetermines if tab key will stopThe TabIndex property determines the order the focus moves as the Tab key is pressedAs controls are created, TabIndex is set in sequenceWhen program starts, focus is on the control with lowest TabIndex9The Tab Order cont.Label controls cannot receive focusDefault value of TabStop for buttons and text boxes is trueDefault value of TabStop for radio buttons is falseIf set to trueTab key takes you to one radio button in a group; Arrow keys to move to another radio button in the group10Setting the Tab OrderSet each control’s TabIndex property in Properties windowCan also use Visual Studio .NET feature to set TabIndexes automaticallyOpen Design windowSelect View / Tab OrderClick on controls in desired tab orderSequence numbers representing tab order on controls are updatedSelect View / Tab Order to hide sequence numbers11Setting the Form’s Location on the ScreenBy default, the form appears in the upper-left corner of the screenSet form’s screen position with StartPosition propertyStartPosition optionsManualCenterScreenWindowsDefaultLocationWindowsDefaultBoundsCenterParent12Creating ToolTipsAdd a ToolTip component to a formToolTip control is placed in component tray at bottom of the Form DesignerComponent tray hold controls that do not have a visual representation at run timeEach control on form has new property: ToolTip on ToolTip1 (assume name of control is ToolTip1)13Before adding Tool Tip14After Adding Tool Tip15Result16Coding for the ControlsYou can change properties as a project executesExamples include clearing out contents of a text box or label resetting the focus changing the color of text17Clearing Text Boxes and LabelsSet Text property to an empty stringEmpty string shown as “”Use the Clear() methodSet the Text property to string.EmptyExamples: txtName.Text = “”;lbl.Message.Text = “”;txtDataEntryBox.Clear();txtMessage.Text = string.Empty;18Resetting the FocusUse the Focus method to reset the focus to a particular controlExample: txtName.Focus();19Set the Checked Property of Radio Buttons and Check BoxesSelect or deselect a control in code by setting the Checked property to true or falseMust use lowercase for true or falseExamples:radRed.Checked = true; //Select buttonchkDisplay.Checked = true; //Make box checkedchkDisplay.Checked = false; //Make box uncheckedchkBox.Checked = ! chkBox.Checked ; // Set to opposite20Setting Visibility at Run TimeUse Visible property to set visibilityExample: lblMessage.Visible = false;Can make visibility depend on selection user makes in a check box or radio buttonExample: lblMessage.Visible = chkDisplay.Checked;21Changing the Color of TextUse ForeColor property to change the color of the textUse BackColor property to change the color around the textThe Color class contains color constantsType keyword Color and a period to see full list of available colorsExamples: txtName.ForeColor = Color.Red;
View Full Document