Click here to Skip to main content
15,878,852 members
Articles / Programming Languages / C#

URLComboBox: A Window Forms Control for Displaying URLs

Rate me:
Please Sign up or sign in to vote.
4.86/5 (14 votes)
25 Feb 2002CPOL2 min read 177K   2.2K   60   16
A Window Forms control for displaying URLs similar to URL combo in Internet Explorer

Sample Image - URLCombo.gif

Introduction

URL combobox is an easy to use control for displaying URLs. I had to develop this when I wrote a rich client interface for a web service.

Here are some features of the control:

  • Autocomplete support like that in Internet Explorer.
  • 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 are 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).

    Image 2

  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 Internet Explorer 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 Internet Explorer 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 control's CreateHandle function is overloaded. In this function, the handle of the edit control is obtained by calling unmanaged 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.

History

  • 26th February, 2002: Initial version

License

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


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralDetecting when the selection is complete Pin
nagarsoft2-May-05 22:09
nagarsoft2-May-05 22:09 
Generalusing the tab key Pin
TigerNinja_30-Sep-04 9:24
TigerNinja_30-Sep-04 9:24 
GeneralCustomised popup Pin
malik1012-Jul-04 0:13
malik1012-Jul-04 0:13 
GeneralSystem.Windows.Forms.Keys.Return Pin
Dr Jeeni4-Jan-04 6:11
Dr Jeeni4-Jan-04 6:11 
GeneralGreat post! Pin
AniaD24-Oct-03 13:04
AniaD24-Oct-03 13:04 
GeneralExtend combo Box for normal dropdown Pin
Anonymous6-Nov-02 5:21
Anonymous6-Nov-02 5:21 
GeneralUnable to select text with the mouse Pin
Member 4919022-Sep-02 16:57
Member 4919022-Sep-02 16:57 
GeneralRe: Unable to select text with the mouse Pin
James T. Johnson22-Sep-02 19:00
James T. Johnson22-Sep-02 19:00 
GeneralUnmanaged code Pin
Ray Cassick18-Jul-02 11:38
Ray Cassick18-Jul-02 11:38 
GeneralRe: Unmanaged code Pin
Heath Stewart9-Mar-03 20:06
protectorHeath Stewart9-Mar-03 20:06 
QuestionWeb portion does not work on Win2k? Pin
Ray Cassick13-Jul-02 15:30
Ray Cassick13-Jul-02 15:30 
AnswerRe: Web portion does not work on Win2k? Pin
Steve Miller20-Oct-03 11:46
Steve Miller20-Oct-03 11:46 
GeneralExend this ComboBox to Datasets Pin
Ben Kloosterman4-Apr-02 17:22
Ben Kloosterman4-Apr-02 17:22 
GeneralCatching KeyEventHandler Pin
Jarrett Vance26-Feb-02 9:53
Jarrett Vance26-Feb-02 9:53 
GeneralRe: Catching KeyEventHandler Pin
Carlos Antollini26-Feb-02 10:21
Carlos Antollini26-Feb-02 10:21 
GeneralRe: Catching KeyEventHandler Pin
George Jacob14-Feb-05 4:49
George Jacob14-Feb-05 4:49 

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

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