C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Label control with gradient property


Posted Date: 29 Jul 2004    Resource Type: Articles    Category: .NET Framework
Author: SubramanianMember Level: Bronze    
Rating: 1 out of 5Points: 4



Introduction

This code demonstrates the most efficient way to implement the gradient property in a winform Label control


public class derLabel : System.Windows.Forms.Label
{
// Declare these variables to specify the left and the right colors of the rectangle
private Color cLeft;
private Color cRight;

// Get/Set the left color
public Color LeftColor
{
get { return cLeft; }
set { cLeft = value; }
}

// Get/Set the right color
public Color RightColor
{
get { return cRight; }
set { cRight = value; }
}

public derLabel()
{
// Default left/right rectangle colors
cLeft = Color.Red;
cRight = Color.Yellow;
}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
// Declare a rectangle with the user specified width and height. As of now, the Upper
// left and top positions have been hardcoded. This can be replaced by creating
// another property for the width and height and specifying the value in the form load
Rectangle oRect = new Rectangle(100,100,this.Width,this.Height);

// Fill the background of label (Rectangle)
LinearGradientBrush oLinearbrush = new LinearGradientBrush(oRect, cLeft,
cRight, Lineargradientmode.horizontal);

// Very important
// You can also use the oLinearBrush.RotateTransform function to change the left
// color and right color (swap them). The input parameter to the above function module
// is an angle which is a float variable. Specify 180 to swap the left and right
// colors. Also, if you loop through the angles, and insert a sleep time, you can
// gradually swap the colors.

// Fill the rectangle with gradient using GDI+
e.Graphics.FillRectangle(oLinearbrush, oRect);
}
}

In the form load,

this.derLbl = new derLabel();

this.derLbl.LeftColor = Color.Blue;
this.derLbl.LeftColor = Color.Yellow;
this.derLbl.Name = "derLbl";
this.derLbl.Text = "Subbu";
this.derLbl.width = unit.pixel(200);
this.derLbl.height = unit.pixel(100);

this.Controls.Add(derLbl);





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Multithreading in .NET # UI thread & Worker threads
Previous Resource: Difference Between vb.net and vb
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use