Click here to Skip to main content
6,595,854 members and growing! (18,748 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate License: The Code Project Open License (CPOL)

VB.NET User Control: LinkTextbox

By George B Gilbert

A textbox that acts like a LinkLabel.
VB, Windows, .NET, Visual Studio, Dev
Posted:18 Apr 2006
Updated:18 Apr 2006
Views:39,861
Bookmarked:19 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 3.30 Rating: 3.65 out of 5

1
1 vote, 12.5%
2
1 vote, 12.5%
3
4 votes, 50.0%
4
2 votes, 25.0%
5

Demo project

Contents

Introduction

The LinkTextbox user control is an aggregate control that combines a textbox, a button, and a label. This control can be configured at design time to handle either email or web addresses with the setting of one property. At run time, this user control lets the user enter an email or web address and then click a button to launch either the default email program or browser depending on how the control is configured.

The label in the LinkTextbox displays a sample email or web address below the textbox. This label can be shown or not shown by setting a property.

Background

The LinkLabel is new in VB.NET. In a user interface, this new control displays the string is its Text property the same way a link is displayed by a browser. When a LinkLabel is clicked, its LinkClicked event is fired and, depending on how the event is coded, either the default email program or web browser is launched (see the article "VB.NET Code Package: Email And Web LinkLabels"). This new functionality is great; however, being a label, the LinkLabel control has a shortcoming.

A LinkLabel does not permit the user to enter an email address or web site URL. When this type of information is, for example, being collected for storage in a database or text file, a textbox has to be used. But, a textbox does not let the user check the information they have entered by having the control launch their email program or browser. What is needed in this situation is a textbox that has the launch capabilities of a LinkLabel.

My original solution for letting the user test what they had entered for an email address or a web site URL was to place a button next to the textbox where the information was entered. When clicked, the button did the launching. It worked great. Then, I added this functionality to a second form and decided that was too much work. Instead of adding and setting up the same textboxes, buttons, and labels (email and web) as I had done on the first form, it occurred to me that, duh!, perhaps I should look at creating a user control. Enter the LinkTextbox.

Using the code

Adding The User Control To Visual Studio

  1. Download the DLL file and, after unzipping, place it in an appropriate folder of your choosing.
  2. In the Visual Studio Toolbox, right click in the My User Controls tab to open a popup menu. (A form must be open for the control tabs to show in the Toolbox.) Click on the Add/Remove Items menu item.
  3. In the Customize Toolbox dialog box, click on the Browse button to open the DLL file.
  4. Click the OK button.

LinkTextbox will be listed on the My User Controls tab. Add the user control to a form by dragging it to a form, the same as you do with any of the controls listed on the Windows Forms tab.

LinkTextbox

The LinkTextbox is an aggregate of a standard textbox, a button, and a label. Which button image and which label text are displayed is set with the Textbox_Type property. This property also sets whether the LinkTextbox will handle email addresses or web URLs.

The LinkTextbox has three custom properties. You set only the ShowSample and Textbox_Type properties at design time. The Textbox_Text property is used at runtime.

Property Type Description
ShowSample Boolean Gets/sets whether or not the sample textbox entry is displayed below the textbox. When set to False, the user control's height is adjusted to its minimum.
Textbox_Text Text Gets/sets the text in the user control's textbox.
Textbox_Type Multiple option Gets/sets whether the control will handle email addresses or web URLs.

The LinkTextbox control raises one custom event. Whenever the text in the control's textbox is changed, the TextboxTextChanged event is raised.

Conclusion

With the LinkTextbox, I can now add data entry textboxes with LinkLabel functionality to my projects quickly. Since the project I'm currently working on calls for this type of functionality often, I expect that this new user control will save me considerable amount of development time. I hope you find it as useful.

Licensing And Limitation Of Liability

You may use all code offered in this article any way you choose without restriction.

Under no circumstances, and under no legal theory, tort, contract, or otherwise, will George Gilbert (hereafter referred to as "software author") or his licensors, be liable to the user of the Double Text library and all code offered in this article (hereafter referred to collectively as "article code") for any damages, including any lost profits, lost data, or other indirect, special, incidental, or consequential damages, arising out of the use or inability to use the article code, and data or information supplied, even if the software author, his licensors, or authorized dealer have been advised of the possibility of such damages, or for any claim by any other party.

License

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

About the Author

George B Gilbert


Member
Click here to see a complete list of my articles.
Occupation: Software Developer
Company: 2 Good Software
Location: United States United States

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Apr 2006
Editor: Sean Ewington
Copyright 2006 by George B Gilbert
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project