SIGN UP MEMBER LOGIN:    
ARTICLE

NumericUpdown Control and LinkLabel Control

Posted by Sivaraman Dhamodaran Articles | Windows Forms C# December 17, 2010
This article explores the usage of NumericUpdown and Linklabel control.
Reader Level:
Download Files:
 

1. Introduction

Linklabel is a kind of label control but it serves the purpose of a hyperlink. With this control you can mark a portion of the label text or even the entire label text with an underline. Clicking on the underlined text raises the event LinkClicked. By providing the handler for this event you can take an action.

NumericUpDown control is a combination of text box and a pair of arrows pointing in opposite directions. Clicking the arrow or holding the mouse pointer on the arrow will increment or decrement the associated value. The current value is displayed on the text box part of the control. When we click the arrow an event ValueChanged is raised for taking the action.

2. NumericUpdown control

The value property of this control is used to retrieve the current numeric value of the control. This value property is changed when the up arrow or down arrow buttons are clicked.

Minimum and Maximum properties are used to set the limits of numeric value. Say for example we want the value to be changed from 0 to 255 (For changing the color value), then Minimum property is set to 0 and Maximum property is set to 255.

Increment property is used to increment or decrement the values in steps. For example if we set the Increment 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 then 5 to 10 next.

The importance of ValueChanged event is already discussed in the introduction.

3. LinkLabel Control

LinkColor property is used to set the color of the Underlined portion of the label text. The underlined portion of the label text is called a link. So linkcolor sets the color for the link when it is not visited yet.

LinkVisitedColor property is used to set the color of the link when it is visited. When the property LinkVisited is set to true, the control picks the color from the LinkVisitedColor property and sets that color to link.

The LinkArea property is used to set a portion of the label text as link. This property determines that based on the letters involved in the label text and specifying the link starting location in terms of character and length of character from that location.

We can take the action for clicking a link portion of the label by providing handler for LinkClicked event.

4. Example – Take a Try

Launch "Visual Studio 2005" and Create Visual C# Windows application. Once the application is created design the form as shown below:

Pic001.JPG

Use the table below to set the properties for the control shown in the above screen shot.  Each control number in the above screen shot is referred in the C.Number column.

Pic002.JPG 

5. Coding

I hope by looking at the dialog design you can understand how it will work and no more explanation is required.

1) Create an event handler for the ValueChanged event of the numericupdown control. In this handler we get the changed value of the control to adjust the width of the text box. Below is the code for that:
//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 you click the up or down arrow button the text box will be resized along its width.

2) 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 given below: 

//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;
}

3) Handle the LinkClicked event for the control number 2. In the handler resize the height of the form to show more controls also set link visited to true. Code is below: 

//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;
}

Note: The Application is created in VS2005. If you have latest version of IDE say "Yes" to the conversion Wizard.

 

Login to add your contents and source code to this article
share this article :
post comment
 

Great. You can put what you did as an article. Something you did for your own interest will be useful for some other person. Bye Man :)

Posted by Sivaraman Dhamodaran Jan 10, 2011

i tried ur app.........i made it more interesting by using a for loop for increasing the text box size...alongwith thread.sleep()....so that it looks like a loading bar..............nd in between i'hv added in many pictures....as if if text box size = 51 then a pic .....textboxsize = 52 then a pic.....it looks like a video playing

Posted by Rishi Khetan Jan 09, 2011

Do I need a Interpreter to understand those code words :) ?

Posted by Sivaraman Dhamodaran Dec 28, 2010

JK

Posted by Abhishek Rapelli Dec 28, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor