Click here to Skip to main content
Click here to Skip to main content

URLComboBox : A window forms control for displaying URL's

, 25 Feb 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
A window forms control for displaying URL's similar to URL combo in IE.
<!-- Download Links --> <!-- Article image -->

Sample Image - URLCombo.gif

<!-- Add the rest of your HTML here -->

Introduction

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.

  1. Add it to the VS.NET tool box.

  2. Place it on any form.

  3. 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 SHAutoComplete function).



  4. Optionally the properties MRUKeyHive and MRUKey can be specified. MRUKeyHive can be MRUKeyHive.LocalMachine or MRUKeyHive.CurrentUser, this indicates the root registry key (HKEY_LOCAL_MACHINE or 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.

Implementation

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 wherever necessary.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rama Krishna Vavilala
Architect
United States United States
No Biography provided

Comments and Discussions

 
GeneralSystem.Windows.Forms.Keys.Return PinmemberDr Jeeni4-Jan-04 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 26 Feb 2002
Article Copyright 2002 by Rama Krishna Vavilala
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid