Open rain resource library 3 (first. net2.0 software)-added the Automatic completion function for the control

Source: Internet
Author: User
I have previously written the first and second articles of the "open rain resource library", which respectively introduce the interface design and design ideas.
The link is as follows:
Open rain resource library (first. net2.0 software) A http://luyu.cnblogs.com/archive/2005/11/25/284281.html
Light rain resource library (first. net2.0 software) 2 http://luyu.cnblogs.com/archive/2005/12/02/289178.html

This article focuses on the specific implementation process of adding the auto-completion function for the control. Let's share it with you. If you think something wrong with me, please leave a message or send me a mail. Thank you.

We know that. net2.0 has added the auto-completion function for many controls. For more information about auto-completion, refer to the description in msdn.
-----------------------------------
If you have used Internet Explorer, you will see the operation process automatically completed. Automatic completion refers to the following behavior: When you input data to a text control, the system automatically recommends the content that you may enter. This function is usually most useful when users need to input long or complex strings. To enable automatic solution completion to take effect, a prerequisite is that some datasets exist, which can be used by the system to find possible matching items.

Now, you can easily add automatic support to the text box and combo box of the Windows Forms Application. Both controls have three new attributes: autocompletemode, autocompletesource, and autocompletecustomsource. You can set autocompletemodeAppend,SuggestOr suggestappend to enable automatic completion. Set autocompletemodeAppendAutomatically append the most likely matching item to the current data. If it is setSuggestWill generate a drop-down list consisting of one or more recommended strings. Suggestappend simultaneously executes these two tasks. This control also requires a source list, which allows users to search for suggestions when entering data. The autocompletesource attribute allows you to select from some system sources, such as filesystem, historylist, recentlyusedlist, allurl, and customsource.

If customsource is selected, a string list must be provided to the autocompletecustomsource attribute. This can be completed at design or runtime. Custom sources are very powerful because they allow you to automatically complete behaviors for business data. For example, when the form is loaded and a category name list is provided to serve as the display source of the combo box and the automatic completion source, you can query the list of product categories from the database. This method allows you to quickly select a category without entering a full category name or manually navigation a long list of items.

-----------------------------------
A lot of friends said that after the Automatic completion is selected, closing the program and opening the program again will disappear, only when the program is executed. Here, I want to tell you that you not only need to select the autocompletecustomsource attribute, but also need to write code or select the attribute settings of the project.
Next I will explain the process in detail.
1. Select autocompletemode as suggest and autocompletesource as autocompletecustomsource.

2. Set the properties of the configuration item, and customize your own key name. I have defined it as "historykey"

3. Enter some simple code. Private void toolstripbutton3_click (Object sender, eventargs E)
{
If (canhistorykey = true) // you can set whether you want to use the auto-completion function.
{
Autocompletestringcollection auto = new autocompletestringcollection (); // define and instantiate the autocompletestringcollection class
If (mylib. properties. settings. Default. historykey! = NULL)
Auto = mylib. properties. settings. Default. historykey; // when the value of historykey is set to null, We need to load the old historical keyword when it is not empty.
Auto. Add (toolstriptextbox1.text. Trim (); // Add a new historical keyword
Mylib. properties. settings. Default. historykey = auto; // update the historical keywords (but not saved)
Toolstriptextbox1.autocompletecustomsource = auto; // Add new historical keywords to the control immediately
}
}

Add toolstriptextbox1.autocompletecustomsource = mylib. properties. settings. Default. historykey to form1_load;

The most important thing is to save these records before closing the window. Otherwise, after you close the program, there will still be no previous records for the next execution. Private void mainform_formclosing (Object sender, formclosingeventargs E)
{
Mylib. properties. settings. Default. Save ();
}

Finally, you must have a clear function private void to clear the history toolstripmenuitem_click (Object sender, eventargs E)
{
Mylib. properties. settings. Default. historykey = NULL;
Toolstriptextbox1.autocompletecustomsource = NULL;
}

(I found that mylib. properties. settings. default. historykey = NULL; and you do not need to use mylib. properties. settings. default. historykey. save (); or .)

Okay. Let's take a look at the effect. It's good. So far, we have added a considerate small feature for the open rain resource library. :)

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.