C # source code for a custom label component

Source: Internet
Author: User
Source

Using System;
Using System.Windows.Forms;
Using System.Drawing;
Using System.Drawing.Drawing2D;
Using System.ComponentModel;

Namespace Wzsbmain
{
<summary>
Summary description for Labelgradient.
</summary>

public class WzsbmainLabel:System.Windows.Forms.Label
{

#region Implementtation member Fields
protected Color gradientcolorone = Color.White;
protected Color gradientcolortwo = Color.Blue;
protected LinearGradientMode LGM = lineargradientmode.forwarddiagonal;
protected Border3DStyle B3dstyle = Border3dstyle.bump;
#endregion

#region Gradientcolorone Properties
[
DefaultValue (typeof (Color), "white"),
Description ("The gradient color."),
Category ("appearance"),
]

Gradientcolorone Properties
Public Color Gradientcolorone
{
Get
{
return gradientcolorone;
}
Set
{
Gradientcolorone = value;
Invalidate ();
}
}
#endregion

#region Gradientcolortwo Properties
[
DefaultValue (typeof (Color), "Blue"),
Description ("The second gradient color."),
Category ("appearance"),
]

Gradientcolortwo Properties
Public Color Gradientcolortwo
{
Get
{
return gradientcolortwo;
}
Set
{
Gradientcolortwo = value;
Invalidate ();
}
}

#endregion

#region LinearGradientMode Properties
LinearGradientMode Properties
[
DefaultValue (typeof (LinearGradientMode), "forwarddiagonal"),
Description ("Gradient Mode"),
Category ("appearance"),
]

Public LinearGradientMode Gradientmode
{
Get
{
return LGM;
}

Set
{
LGM = value;
Invalidate ();
}
}
#endregion

#region Border3DStyle Properties
Border3DStyle Properties
[
DefaultValue (typeof (Border3DStyle), "Bump"),
Description ("BorderStyle"),
Category ("appearance"),
]

Hide BorderStyle inherited from the base class
New public Border3DStyle BorderStyle
{
Get
{
return b3dstyle;
}
Set
{
B3dstyle = value;
Invalidate ();
}
}
#endregion

#region removed Properties

Remove BackColor Property
[
Browsable (False),
Editorbrowsable (Editorbrowsablestate.never)
]
public override System.Drawing.Color BackColor
{
Get
{
return new System.Drawing.Color ();
}
set {;}
}

#endregion


protected override void OnPaint (System.Windows.Forms.PaintEventArgs e)
//  {
Graphics gfx = e.graphics;
Border3DStyle B3dstyle = border3dstyle.bump;
Border3dside b3dside = Border3dside.all;
//
Rectangle rect = new Rectangle (0,0,this. Width,this. Height);
//
Dispose of Brush Resources
using (LinearGradientBrush LGB = new LinearGradientBrush (rect, GRADIENTCOLORONE,GRADIENTCOLORTWO,LGM))
Gfx. FillRectangle (Lgb,rect);
//
3d border
Controlpaint.drawborder3d (Gfx,rect,b3dstyle,b3dside);
//
//
Call the OnPaint method of the base class
Base. OnPaint (e);
//
//  }

protected override void OnPaintBackground (System.Windows.Forms.PaintEventArgs pevent)
{
Graphics GFX = pevent. Graphics;

Rectangle rect = new Rectangle (0,0,this. Width,this. Height);

Dispose of Brush Resources
using (LinearGradientBrush LGB = new LinearGradientBrush (rect, GRADIENTCOLORONE,GRADIENTCOLORTWO,LGM))
Gfx. FillRectangle (Lgb,rect);

Controlpaint.drawborder3d (Gfx,rect,b3dstyle);
}


}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.