Source Editing

 <  Day Day Up  >  

The most important window you will work with in the IDE is the source code window. For sake of clarity, the source window also displays different designers based on the file format of the file being edited, but this discussion focuses on the source code window as it relates to C# source code files.

Code Outlining

Outlining is a feature that places logical code blocks into collapsible sections similar to that of a tree control. By default, the source code for new projects is displayed in its expanded state, except for code that is off limits such as Windows Form designer-generated code. By right-clicking within the source code window or selecting the Edit, Outlining pop-up menu from the main menu, you can view a list of outlining commands. The Toggle Outlining Expansion collapses a section to a single line and places an ellipsis at the end of that line or expands the section if it is already collapsed . This action is similar to clicking the tree node control along the left side of the source window.

The Toggle All Outlining command collapses all code blocks or expands them if they are already collapsed. Finally, the Collapse to Definitions item parses the source code file and collapses the code so that only method declarations are visible. For those who are familiar with C++, this view is similar to that of a header file. You can also disable outlining at any time by selecting the Stop Outlining menu item.

Outlining uses C# language constructs to determine regions to create. In other words, regions are created for matching braces, including those denoting a conditional control block such as an if statement or do / while block. You can also define your own regions by using the #region and #endregion preprocessor directives. The following example demonstrates how to create a region that can be collapsed for member variables within a class:

 
 namespace _MyProject {     public class Form1 : System.Windows.Forms.Form     {         #region Windows Form Control Variables         private System.Windows.Forms.DataGrid dataGrid1;         private System.Windows.Forms.MenuItem menuItem1;         private System.Windows.Forms.MenuItem mnuExit;         #endregion     } } 

IntelliSense

IntelliSense is the technology used by the IDE that displays help information within a tooltip or a selectable list box as you type in source code. For instance, entering a variable name that represents a class and following it with the dot operator for member access displays a list box that allows you to choose the proper class method or variable. As you continue typing, the list box changes to reflect the closest match based on the current typed characters . At any time the list box highlights the member you are looking for, press the Tab key to complete the word. You can additionally use the up- and down-arrow keys or PageUp and PageDown keys to navigate to the correct member.

As you enter a parenthesis denoting a method call, a specialized tooltip appears listing the possible method parameters. If any other overloaded versions of the method exist, you see an up/down control on the left side of the tooltip. You can use the up- and down-arrow keys to select the proper overloaded version that you want to use, and as you enter each parameter, the tooltip marks your location using a bold typeface.

IntelliSense also allows you to view information about a data type or method parameters at any time using the IntelliSense toolbar buttons or menu item accessed through the Edit menu. Clicking away for the current editing position while editing source code removes any tooltip or list box that is displayed. If you place your cursor back to that position and access one of the IntelliSense menu or toolbar items, the tooltip or list box reappears.

Bookmarks

Bookmarks allow you to mark positions within your code that you want to frequently access while working in your project. The bookmark commands appear on the toolbar, easily recognizable by a group of blue flags, or on the Edit main menu. If you position your cursor at a particular line in the source window and select the Toggle Bookmark command, a cyan colored marker appears in the left-side margin of the source code window. If you place an additional bookmark within the same file, you can switch between the locations by using the next and previous bookmark commands. They only navigate to bookmarks within the same source file, which means you are unable to toggle between two bookmarks if they are in different source files.

Creating Task List Shortcuts

The Task List window is generally used to display warnings and errors that arise whenever you compile your project. Clicking on the warning or error takes you to the corresponding line in the source code, allowing you to fix it. You can also use the source code window to create automatic entries within the task list to create shortcuts. To create a task list shortcut, place the cursor on the line to create the shortcut to and click on the Add Task List Shortcut menu item accessed through the Edit, Bookmarks menu. To view the list of shortcuts within the task list, right-click on the Task List window and select Show Tasks, Shortcuts.

You can also automatically create task list shortcuts by creating specialized comments. To automatically place a shortcut into the task list, add the single-line comment operator ( // ); followed by a task list keyword such as TODO , HACK , or UNDONE ; followed by the text to display in the task list. You can optionally create your own keywords by clicking on Tools, Options from the main menu; selecting the Environment, Task List property page; and filling in the Name field with a new keyword. You can set the priority to low, medium, or high.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net