可以显示渐变背景色的Lable

///如未特别说明,本人所发表的技术文章都为原创, 任何人引用都请注明出处,并包含本声明
///作者: CSDN网名alias88,邮件: [email protected] ,QQ:63343

using

System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Drawing.Drawing2D;

using System.Windows.Forms;

namespace upLibrary.upControls

{

///

1<summary>
2
3///  可以显示渐变背景色的Lable 
4
5///  </summary>

public class upLabel : System.Windows.Forms.Label

{

///

1<summary>
2
3///  必需的设计器变量。 
4
5///  </summary>

private System.ComponentModel.Container components = null ;

private Color startColor = Color.Wheat ;

private Color endColor = Color.LimeGreen;

private Brush baseBackground= null ;

private bool showGradient= true ;

private float mAngle=75;

private bool _ShowText;

public upLabel()

{

InitializeComponent();

}

///

1<summary>
2
3///  清理所有正在使用的资源。 
4
5///  </summary>

protected override void Dispose( bool disposing )

{

if ( disposing )

{

if (components != null )

{

components.Dispose();

}

}

base .Dispose( disposing );

}

#region 组件设计器生成的代码

///

1<summary>
2
3///  设计器支持所需的方法 - 不要使用代码编辑器 
4
5///  修改此方法的内容。 
6
7///  </summary>

private void InitializeComponent()

{

//

// upLabel

//

this .Size = new System.Drawing.Size(144, 21);

}

#endregion

protected override void OnPaintBackground(PaintEventArgs e)

{

LinearGradientBrush lbs;

base .OnPaintBackground(e);

if ( this .Disposing ) return ;

if (baseBackground == null )

{

if (ShowGradient)

{

lbs = new LinearGradientBrush(

ClientRectangle ,

StartColor ,

EndColor,

Angle);

baseBackground=lbs;

}

else if (BackgroundImage != null )

{

baseBackground = new TextureBrush(BackgroundImage);

}

else

{

baseBackground = new SolidBrush(BackColor);

}

}

e.Graphics.FillRectangle(baseBackground, ClientRectangle);

e.Graphics.Flush();

}

[

Category("渐变"),

DefaultValue( true ),

Description("指示是否显示文本。")

]

public bool ShowText

{

get

{

return _ShowText;

}

set

{

if ( value != _ShowText)

{

_ShowText = value ;

if (baseBackground != null )

{

baseBackground.Dispose();

baseBackground = null ;

}

Invalidate();

}

}

}

[

Category("渐变"),

DefaultValue( true ),

Description("指示背景是否应显示颜色渐变。 ")

]

public bool ShowGradient

{

get

{

return showGradient;

}

set

{

if ( value != showGradient)

{

showGradient = value ;

if (baseBackground != null )

{

baseBackground.Dispose();

baseBackground = null ;

}

Invalidate();

}

<SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: 新宋体; mso-hansi-fon

Published At
Categories with Web编程
Tagged with
comments powered by Disqus