|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionWhen using an application that presents a lot of text in controls, users will expect to be able to search for text phrases by pressing Ctrl-F. Unfortunately for the application developer, while adding the control is just a matter of dragging it from the toolbox, adding the search functionality is a bit more work. To solve this, I developed a lightweight class library, SearchableControls, that contains ready-to-use Find featuresThe search dialog is designed to behave like standard Windows applications such as Notepad. Features include;
Additional features
The main feature of these controls is the search function. However, I have also added some functionality conspicuously absent from the basic controls. For Also available is a
I have also added a shortcut key for Ctrl-A to select all the text in the controls (other than the extension of Using the codeGetting the controls into the toolboxFrom the DLL:The controls can be used directly from the binary library (SearchableControls.dll). In Visual Studio 2005, right click on the form designer toolbox, and select Choose Items. Then click the Browse button, and navigate to and open the .dll. Click OK, and the four controls will now be added somewhere to the toolbar. From the source:Download the source, and add the SearchableControls.vcproj to your solution. Build the solution, and the controls should appear in your toolbox automatically. If this doesn't happen, closing and re-opening Visual Studio can encourage it.
Getting the controls into your formThis is a matter of dragging them to your form from the designer toolbox in the usual way. Build and run your application, click on the new control, press Ctrl-F, or right click->Find, and you will see the Find dialog. Typing the text and pressing Return or clicking the Search button will search the contents of the control. Pressing F3 in the Find dialog or in the control will search for the next occurrence of the string. Once the remainder of the document has been searched, searches will take place from the start of the document.
Adding the Find entries to the parent form menuUsers will expect to see Find under the form's Edit menu. In the designer, add the Edit->Find menu item to your form and give it a private void findToolStripMenuItem_Click(object sender, EventArgs e)
{
SearchableControls.Utility.OpenFindDialog(Controls);
}
Now, add an Edit->Find Again menu item, and give it a private void findAgainToolStripMenuItem_Click(object sender, EventArgs e)
{
SearchableControls.Utility.FindNext(Controls);
}
These functions allow multiple searchable controls on a form as they will select the most appropriate based on focus. However, all controls apply the interface How it worksEach control supplies A note about HideSelectionMost Framework controls have a Unfortunately, a slight flicker is visible when this property is altered. One way to stop that is to set Customizing the libraryCustomizing the Find dialogIt is a simple matter for developers to customize the appearance of the Find dialog using Visual Studio's designer. Unwanted controls can simply be hidden from the view. Extending other controls to be searchableDrag a This event handler has a minimum function it is required to perform. It is expected to search its content from after the current selection until the end, and then from the top of the content until the current selection. It is expected to match text against the regular expression supplied in Using regular expressions frees the controls from having to process case sensitivity and other exotic search options such as wildcards. As mentioned above, if you are deriving from a Framework control, and using selection to indicate search results, you will probably need to turn off Further developmentThe idea of supplying the expected basic functionality to controls could be explored further. History
|
||||||||||||||||||||||