![]() |
Languages »
VB.NET »
General
Intermediate
License: The Code Project Open License (CPOL)
VB.NET User Control: LinkTextboxBy George B GilbertA textbox that acts like a LinkLabel. |
VB, Windows, .NET, Visual Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

Demo project
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.
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.
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.
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.
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.
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.
General
News
Question
Answer
Joke
Rant
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 Web19 | Advertise on the Code Project |