Chapter 1 objectivesDescribe the process of visual program design and development Explain the term object-oriented programmingObject Oriented Programming (OOP)—C#, Java, Visual Basic User controls the sequenceUser actions cause events to occur which trigger methods Explain the concepts of classes, objects, properties, methods, and events List and describe the three steps for writing a C# programThree steps(planning)Design the user interfacePlan the propertiesPlan the C# codeThree steps(planning)Define user interfaceSet the propertiesWrite the codeDescribe the various files that make up a C# project.sln **Form.cs Program.cs **Form.resx **Form.Designer.cs Identify the elements in the Visual Studio environmentForm designerEditor for entering and modifying C# codeCompilerDebuggerObject BrowserHelpDefine design time, run time, and debug timeDesign TimeDesign user interface (forms)Write codeRun TimeTesting projectRunning projectDebug TimeRun-time errorsPause program executionWrite, run, save, and modify your first C# programIdentify syntax errors, run-time errors, and logic errorsSyntax errorsBreaking the rules of the languageRun-time errors or exceptionsProgram halts due to statements that cannot execute Logic errorsProgram runs but produces incorrect resultsLook up C# topics in HelpForms controls Objects Properties Methods Events ClassesC# Versions Express Edition, Standard Edition, Professional Edition, Team SystemToolbox MainDocument Window Solution Explorer Property WindowSnap Line基准线Comment statements 注释// /**/braces { }underscore (_)semicolon (;)parentheses 括号Renaming a ControlChange the name of the control in the design windowSwitch to Editor window 编辑窗口Right-click name of event-handling methodSelect Refractor/RenameEnter new name in Rename dialog boxClick Apply in Preview Changes dialog boxIf you change the filename first, the IDE automatically changes the name of the class(改文件名) MainForm exitButtonChapter 2 ObjectivesUse text boxes, masked text boxes, rich text boxes, group boxes, check boxes, radio buttons, and picture boxes effectivelySet the BorderStyle property to make controls appear flat or three-dimensionalSelect multiple controls and move, align, and set common properties for themMake your projects easy for the user to understand and operateDefine access keysSet Accept and Cancel buttonsControl the tab sequence, resetting the focus during program executionUse ToolTipsClear the contents of text boxes and labelsMake a control visible or invisible at run time by setting its Visible propertyDisable and enable controls at design time and run timeChange text color during program executionConcatenate (join) strings of textDownload the Line and Shape controls, add them to the toolbox, and use the controls on formsTextBoxTextTextAlign(left/right/center):文本对齐方式WordWrap(true/false):允许长单词换行Multiline(true/false):是否可以显示一行以上数据MaskedTextBox(masked:隐蔽的):输入格式化的数据MaskRichTextBox:输入多行文本DetectUrls:将Url自动转化为网址LoadFile:load .rtf fileGroupBox:EnabledTextCheckedBox:CheckedEvent:CheckedChangedRadioButton:CheckedPictureBox:ImageSizeMode(Normal/StretchImage/Zoom/AutoSize/CenterImage):是否适应画框大小BoarderStyle(None/FixedSingle/Fixed3D)Keyboard Access Keys(Hot Keys):&(Alt+underlined word)AcceptButton:EnterCancelButton:EscTab Order:TabStop(true/false)TabIndex(0——)ToolTip on ToolTip1(对每个控件加标记)清空:1、“”2、string.empty 3.(textBox)TextBox.clear();TextBox.focus();Environment.NewLineEnabled visible ForeColor BackColorChapter 3 ObjectivesDeclare variables and constantsSelect the appropriate scope for a variableConvert text input to numeric valuesPerform calculations using variables and constantsConvert between numeric data types using implicit and explicit 强制conversions Round decimal values using the decimal.Round methodFormat values for output using the ToString methodUse try/catch blocks for error handlingDisplay message boxes with error messagesAccumulate sums and generate countsConstantsconst decimal DISCOUNT_RATE_Decimal=.15M;decimal MByte bool DateTime decimalDecimal:business applicationFloat/double:scientific applicationIntrinsic constantScope and Lifetime of VariablesNamespaceAlso referred to as globalClass-levelLocal 在方法中使用Block 在{ }中使用All constants should be declared at class level文本转化为数字:quantityInteger=int.parse(quantityTextBox.text);数字转化为文本:quantityTextBox=quantityInteger.toString();Format data:C:currency;N:number;N3:三位小数;F ;D ;Hierarchy Increment Decrement Prefix notation Postfix notation求幂:Math.pow(x,y);Implicit conversion:C# has no implicit conversions to convert from decimalExplicit conversion(casting):numberDecimal = (decimal) numberFloat;//可以!!!或:numberDecimal=Convert.ToDecimal(numberFloat);Rounding numbersresultDecimal = decimal.Round(amountDecimal, 2); //if 5, to even number Output:TextBoxHandling exception:Try...catch...finally...FormatExceptionInvalidCastExceptionArithmeticExceptionSystem.IO.EndofStreamExceptionOutOfMemoryExceptionExceptionMessageBox.Show(TextMessage,TitleBarText,MessageBoxButtons,MessageBoxIcon);TextBox.SelectAll();TextBox.Focus();Test each Parse method(using try-catch block)Chapter 4 objectivesUse if statements to control the flow of logicTest the Checked property of radio buttons and check boxes using if statementsPerform validation on numeric fields using if statementsUse a switch structure for multiple decisionsUse one event handler to respond to the events for multiple controlsCall an event handler from other methodsCreate message boxes(enhancing) with multiple buttons and choose alternate actions based on the user responseDebug projects using breakpoints, stepping program execution, and displaying intermediate resultsComparing stringsCompare strings with equal to (==) and not equal to (!=) operatorspareTo(bString)Comparing Uppercase and Lowercase CharactersTextString.ToUpper(); TextString.ToLower();Priority: ! && ||Checking the State of a Radio Button Group: if...else if...Checking the State of Multiple Check Boxes: if...if...escape sequence(转义字符)Enhancing MessageBox:DialogResult whichButtonDialogResult;whichButtonDialogResult=MessageBox.Show(“content”,”title”,MessageBoxButtons.OKCancel, MessageBoxIcon.Warning,MessageBoxDefaultButton.Button1,MessageBoxOptions.RightAlign) If(whichButtonDialogResult==DialogResult.OK){}Performing Multiple Validationsif (nameTextBox.Text != ""){try{unitsDecimal = decimal.Parse(unitsTextBox.Text);if (freshmanRadioButton.Checked || sophomoreRadioButton.Checked|| juniorRadioButton.Checked || seniorRadioButton.Checked){// Data valid - - Do calculations or processing here.}else{MessageBox.Show(“Please select grade level.”, “Data Entry Error”, MessageBoxButtons.OK);}}catch(FormatException){//Display error message}}Sharing an event handlerDuplicateCalling Event Handlers“Call”the method from another method by naming the methodChapter 5 ObjectivesCreate menus and submenus for program controlDisplay and use the Windows common dialog boxes(ColorDialog,FontDialog) Create context menus for controls and the formWrite reusable code in methods and call the methods from other locationsMenuToolStripMenuItemsToolStripComboBoxesToolStripSeparatorsToolStripTextBoxesProperties:enabled,checked,showShortcutKeyModal versus Modeless WindowsA dialog box is said to be modalThe box stays on top of the application and must be responded toUse the ShowDialog methodA window that does not require response is said to be modelessUse the Show methodNo other program code can execute until the user responds to, hides, or closes a modal formModeless—Close destroys the form instance and removes it from memoryModal—Close only hides the form instanceIf the same instance is displayed again, any data from the previous ShowDialog will still be therecolorDialog/fontDialogSet initial valuescolorDialog1.Color = textBox1.BackColor;colorDialog1.ShowDialog();textBox1.BackColor = colorDialog1.Color;If the user presses Cancel, property setting for the objects will remain unchanged(否则有可能会自行改变)Context menusA context menu does not have a top-level menu, only menu items(没有最顶级菜单,只有具体的菜单项)为特定的项添加contextMenuStrip(e.g. Form, label,button...)Writing General MethodsAn exampleprivate decimal sumPrice(decimal numberDecimal)Ref parameter(调用方法中赋初值)直接改变调用方法中的。