Visual Studio. NET tips)

Source: Internet
Author: User

1. Quick Switch Tab


During application development, we often open multiple form designers, class files, and other types of files. When multiple files are switched over with the mouse, we usually need to click several times, you may use the shortcut key Ctrl + TAB or SHIFT + Ctrl +
Tab to switch. You can also drag the file title to rearrange it. 2. view multiple files
In. net, you can view two or more files at the same time, just drag the file you want to view to the right or bottom of the IDE in the Open tab, you can view the document vertically or horizontally.
3. view different parts of the same document
When different parts of the same document are requiredCodeYou can view different parts of the Code in the split code window. Move the cursor over the scroll bar in the upper-right corner of the code window, and drag the two-way arrow down to the position you want to split. Now you can move the scroll bar to view different parts of the Code.

4. Manage reusable code snippets


Some common code snippets are used repeatedly in different projects or solutions, such as file creation instructions and database connection strings. You can use the toolbox to reuse the code: select the code snippet to be reused; drag the selected code to the general card of the toolbox, and The toolbox will display "text ......" (You can right-click and rename the name from the menu.) When using the tool, click the mouse at the position where the code is inserted, double-click the code to be inserted in the toolbox (you can also drag the code snippet to the position to be inserted ).

5. Use progressive search
Code Search Method,. you can use "Search" in the editing menu to search for a specific string, or use "Search symbol" to find a specific method or attribute, however, "progressive search" may be rarely noticed. "progressive search" can be searched in the currently opened code based on the characters you typed. Use the shortcut Ctrl + I to display a downward arrow and telescope pattern in the code window. The status bar under ide displays the word "progressive search" and type the characters to search, the system automatically locates the position where the next character appears. You can press Ctrl + I to find the position where the next character appears. You can press SHIFT + Ctrl + I to continue searching the position where the previous character appears.

6. enumerate controls in the container to handle control events


We know that Program When using events, an event handler (Event Processing Method) must be provided, which is usually implemented by delegation. However, if you want to implement the same processing method for the same events of the same type of controls in a container, you may use the controls in the container to enumerate and specify relevant delegates to process the events. Maybe you will say, why is it so complicated? I can specify the event processing method in the properties of the control, but when there are many controls in the container, you can also add new controls during the design process. It is very troublesome to specify them one by one.
As shown in, there are two text boxes in the application. I want to specify the enter, leave, and validating events for the two text boxes (username and password). When the text box gets the focus, it changes its background color, when you exit, the system text color is restored, and the validating method is used to check whether the text box content is empty. If it is empty, errorprovider is used to display the error message.
I use addeventhandler to enumerate controls in the form. When it is a text box, specify the event Delegate. The Code is as follows:

  /**/ ///   <Summary>  
/// Enumerate the controls in the container and add the event processing delegate for the text box
///   </Summary>  
///   <Param name = "pnl"> Container </Param>  
Private   Void Addeventhandler (control pnl)
{
Foreach (Control CTRL In Pnl. Controls)
{
If (CTRL Is Textbox)
{
CTRL. Enter + = New Eventhandler ( This . Txt_enter );
CTRL. Leave + = New Eventhandler ( This . Txt_leave );
CTRL. textchanged + = New Eventhandler ( This . Txt_textchanged );
CTRL. Validating + = New Canceleventhandler ( This . Txt_validating );
}
If (CTRL. haschildren)
Addeventhandler (CTRL );
}
}
 
 
/**/ ///   <Summary>  
/// How to handle the enter event in the text box
///   </Summary>  
///   <Param name = "sender"> </param>  
///   <Param name = "E"> </param>  
Private   Void Txt_enter ( Object Sender, system. eventargs E)
{
Textbox TB = (Textbox) sender;
TB. backcolor = Color. blanchedalmond;
}
 
/**/ ///   <Summary>  
/// How to handle leave events in the text box
///   </Summary>  
///   <Param name = "sender"> </param>  
///   <Param name = "E"> </param>  
Private   Void Txt_leave ( Object Sender, system. eventargs E)
{
Textbox TB = (Textbox) sender;

TB. backcolor = Color. fromknowncolor (knowncolor. Window );
}
 
/**/ ///   <Summary>  
/// How to handle the validating event in the text box
///   </Summary>  
///   <Param name = "sender"> </param>  
///   <Param name = "E"> </param>  
Private   Void Txt_validating ( Object Sender, system. componentmodel. canceleventargs E)
{
Textbox TB = (Textbox) sender;
Errorprovider1.seterror (TB, "" );
If (Tb. Text. Length = 0 )
{
Errorprovider1.seterror (TB, " Please input any text! " );
TB. Focus ();
}
}
Then add the addeventhandler (this) Statement to the form1 constructor:

Public Form1 ()
{
//  
// Required for Windows Form Designer support
//  
Initializecomponent ();

Addeventhandler ( This );
}
SELF: http://www.cnblogs.com/jeet/archive/2005/04/10/134934.html (containing porn description)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.