1. Introduction to NumericUpDown and LinkLabel Control
LinkLabel Control is a kind of Label Control but it serves the thought of a hyper-link. With this LinkLabel Control, you can mark portion of the Label text or the full Label text with an underline. Clicking on the underlined text raises the
LinkClicked
Event. By adding the handler for this event, one can take a suitable action. NumericUpDown Control is a mix of the text box and a pair of arrows pointing in the opposite orders. Clicking the arrows of the NumericUpDown or holding down the mouse pointer on the arrow will increments or decrements the linked value. The linked value is shown on the text box part of the Control. When we click the arrow, C# raises
ValueChanged
event allowing the C# developer to take the required action.
2. Properties of NumericUpDown Control
We use the
Value Property
of the NumericUpDown Control to fetch the present numeric value of the Control. C# changes this property value when a user clicks the up or down arrow buttons.
The
Minimum
and
Maximum
Property sets the limits for the numeric value of the
NumericUpDown
Control. Say, for example, if we want to change the value in the range between 0 and 255 (For RGB color value), then we set
Minimum
Property to 0 and
Maximum
Property to 255.
The
Increment
Property of the NumericUpDown Control rises or drops the value of the control in steps. For example, if we set the
Increment
Property to 5, and if the current value of the Control is 0, clicking twice the up-arrow button will change the Value Property to 0 to 5 first and later 5 to 10.
We previously discussed the importance of ValueChanged event in the introduction section of this article.
3. Properties of LinkLabel Control
We use
LinkColor
Property of the LinkLabel Control sets the color of the underlined portion of the label text. The underscored portion of the label text is known as a link. So LinkColor sets the color for the link when it is not yet visited.
The LinkLabel’s
LinkVisitedColor
Property sets the color of the already visited links. At run time, when we set the LinkVisted Property to true, C# will use the color in this property to change the color of the LinkLabel Control’s text.
We use the
LinkArea
Property of the LinkLabel to set specific part of the label text as a Hyper-Link. We can decide what part of the text we should mark as Hyper-Text by pointing out the starting point of the link in terms of character position and length of character from that starting point.
The Control raises the LinkClicked Event when user clicks the Link. A Developer can handle this event to take appropriate action.
The below youtube video gives introduction to NumericUpDown and LinkLabel Controls:
4. Let us create our Example
To start the application, we have to launch Visual Studio 2005 and create Visual C# Windows Application. Once the IDE done with creating the application, we design the form as shown below:

NumericUpdown and LinkLabel Example
One can use the table below to set the properties for the controls shown in the above screenshot. The first column in the below table refers the control number in the above screen.

NumericUpdown and LinkLabel Example – Control Properties
The below youtube video shows designing the form for this example”
5. Programming LinkLabel and NumericUpDown Control
5.1 ValueChanged Event Handler of NumericUpDown Control
Create an Event Handler for the
ValueChanged
Event of the NumericUpDown Control. In this C# Event Handler, we get the changed value of the NumericUpDown Control and use that value to adjust the width of the text box. Below is the code for that:
1 2 3 4 5 6 7 |
//Updown_001: Increase width of the Text box //based on the current value of the UpDown Control private void nuUpDown_ValueChanged(object sender, EventArgs e) { txtBx.Width = (int) nuUpDown.Value; } |
Now, if we click the up or down arrow button, the example will adjust the width of the text box. In the above code, the Value Property of the Control returns the current value of the Control. Also note, we type cast it as integer before setting the width of the TextBox Control.
5.2 LinkClicked Handler of LinkLabel Control
Next we handle the
LinkClicked
Event for the control number 1. In the handler, we first show a message box and then set the
LinkVisited
property to true. This will set the different color for the link. Code is below:
1 2 3 4 5 6 7 8 |
//LinkLabel_001: Handler for the Link clicked event. //Display a message when the link clicked. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { MessageBox.Show("Hello There.."); linkLabel1.LinkVisited = true; } |
Finally, we handle the
LinkClicked
Event for the control number 2. In the handler we resize the height of the form to show more controls also we set
LinkVisited
Property to true. Code is below:
1 2 3 4 5 6 7 8 9 10 11 |
//LinkLabel_002: Handler for the Link clicked //event. Display the remaining controls. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { //001: Set that the link is visited linkLabel2.LinkVisited = true; //002: Resize the form to show all the controls this.Height = 200; } |
The youtube video below shows code implementation:
6. Completed Example & Download
Below is the complete code example for the Form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace UpDownLinkLabel { public partial class frmLinkLabel : Form { public frmLinkLabel() { InitializeComponent(); } //LinkLabel_001: Handler for the //Link clicked event. Display a message when //the link clicked. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { MessageBox.Show("Hello There.."); linkLabel1.LinkVisited = true; } //LinkLabel_002: Handler for the Link clicked //event. Display the remaining //controls. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { //001: Set that the link is visited linkLabel2.LinkVisited = true; //002: Resize the form to show all //the controls this.Height = 200; } //Updown_001: Increase width of the Text box //based on the current value //of the UpDown Control private void nuUpDown_ValueChanged(object sender, EventArgs e) { txtBx.Width = (int) nuUpDown.Value; } } } |
Source Code: Download from Google Drive
- Custom Foreach Example Using IEnumerator and IEnumerable
- C# PictureBox Control and Image Load Progress
Categories: C#
Tags: LinkLabel::LinkArea, LinkLabel::LinkColor, LinkLabel::LinkVisited, NumericUpDown Minimum Maximum, NumericUpDown Value