<!-- Download Links -->
<!-- Article image -->
<!-- Add the rest of your HTML here -->
URL combo box is an easy to use control for displaying URLs. I had to devlop
this when I wrote a rich client interface for a web service.
Here are some features of the control :-
Autocomplete support like that in IE.
Automatic management of MRU list. The control automatically fills the combo
list from a specific registry key (specified as a property) and also adds any
URL entered by the user which is not already in the registry.
Using the control
It is very simple to use the control.
Add it to the VS.NET tool box.
Place it on any form.
Set the AutoComplete options by specifying the Flags property. This controls
what is displayed in the autocomplete popup list. For example in the image
shown below the Flags property is set so that the URL history, most recently
typed URLs and the file system is included in the autocomplete list. (The
various flags are documented in the C# xml documentation and correspond
to the flags that can be specified to
Optionally the properties
MRUKeyHive can be MRUKeyHive.LocalMachine or
MRUKeyHive.CurrentUser, this indicates the root registry key
HKEY_CURRENT_USER) to use.
MRUKey is a string value
that specifies the path of sub key under this key. The control looks for value
names of the form urlXXX under this key (where XXX is a number e.g url1, url2)
and uses the data from these registry values to fill the list box. This is the
same way as IE manages the list of MRU URLs. The control also updates the
registry key based on any new URL typed.
The default values of these properties are set to the registry key
which IE uses for storing its most recently used URLs.
That's all that needs to be done to use this control. In fact the demo VB app which is an internet browser has only one line of user
written code. Everything else like resizing and layout of controls is managed by
the window forms framework.
The implementation is pretty simple. The controls
CreateHandle function is
overloaded. In this function the handle of the edit control
is obtained by calling unamanaged
GetComboBoxInfo function. The handle
thus obtained is passed to
SHAutoComplete function again through PInvoke. The
MRU list is managed by using the convenient Microsoft.Win32.Registry and
Microsoft.Win32.RegistryKey classes. The code contains the C# doc comments