Beruflich Dokumente
Kultur Dokumente
Designing a Form
Control Properties
The properties window displays the for the currently selected control To change the property, enter the value into the textbox of the property To change the properties for two or more controls of the same time , select the controls then select the common properties A brief explanation of the property appears on the bottom of the window Properties can be sorted alphabetically and by category
Common Property
Name Text Acceptbutton Cancelbutton Startposition Enabled Readonly Tabindex Tabstop Textalign
Introduction to coding
Object oriented programming Instantiation Classes Properties defines characteristics and data Methods determines the operations Events and members
Common Events
Control click double click enter leave Form Load Closing Closed
Event Concepts
Windows forms applications work by responding to events that occur on objects To indicate how an application should respond to an event , you code an event handler, which a special type of method that handles the event To connect the event handler to the event, visual studio automatically generates a statement that wires the event to the event handler An event can be an action thats initiated by the user like the click event , or it can be an action initiated by program code like the closed event
2.
3.
In the form designer, double click the control. The code window opens and generates the declaration for the method that handles the event, and places the cursor within its declaration Type the C# code between the { } You can return to the designer by clicking the view designer button
Load Event
The method declaration for the event handler thats generated when you double click on an object in the form designer includes a method name that consists of the object name, an underscore , and the event name The event handler is stored in the cs file in the form Most of the code thats generated when you design a form, including the statement that wires the event to the event handler, is stored in the designer.cs file in the form
IntelliSense
Lists keywords , data types , variables, objects, and classes as you type so you can enter them correctly When you highlight an item in the completion list , a tooltip is displayed with the information about the item Pressing the ctrl key will open the code behind the list
Coding rules
Use spaces to separate the words in each statement Use exact capitalization for all keywords, class names, object names, variable names, End each statement with a semicolon Each block of code must be enclosed in {}
Syntax Errors
Visual studio checks the syntax of your C# code as you enter it A wavy underline is highlighted in a syntax error All errors are listed in the error list
Comments
Used to document a part of a program Can be single line(//) or multiline(/* */)
Snippets
To insert a code snippet, right click in the code editor and select the insert snippet command from the resulting menu. Then, double-click the folder that contains the code snippet you want to insert, select the code snippet and then press the tab or enter key You can also insert a code snippet by selecting an item from a completion list that has a code snippet and then pressing the tab key twice To surround existing code with a code snippet, select code, right-click on it, and select the surround with command from the resulting menu, then select the appropriate snippet Code snippets manager displays a dialog box that list the available snippets
Runtime errors
Fixing errors are called debugging When errors are encountered, it enters break mode The exception assistant suggests solutions