.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
可以显示渐变背景色的Lable

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

///如未特别说明,本人所发表的技术文章都为原创, 任何人引用都请注明出处,并包含本声明
///作者: 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

{

  /// <summary>

  /// 可以显示渐变背景色的Lable

  /// </summary>

  public class upLabel : System.Windows.Forms.Label  

  {

    /// <summary>

    /// 必需的设计器变量。

    /// </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();

    }

 

    /// <summary>

    /// 清理所有正在使用的资源。

    /// </summary>

    protected override void Dispose( bool disposing )

    {

      if( disposing )

      {

        if(components != null)

        {

          components.Dispose();

        }

      }

      base.Dispose( disposing );

    }

 

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

    /// <summary>

    /// 设计器支持所需的方法 - 不要使用代码编辑器

    /// 修改此方法的内容。

    /// </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();

        }

      }

    }

 

 

    [

    Category("渐变"),

    Description("指定渐变的角度")

    ]

    public float Angle

    {

      get

      {

        return mAngle;

      }

      set

      {

        mAngle = value;

        if (baseBackground != null && ShowGradient)

        {

          baseBackground.Dispose();

          baseBackground = null;

        }

        Invalidate();

      }

    }

 

 

 

    [

    Category("渐变"),

    Description("指定渐变的开始颜色")

    ]

    public Color StartColor

    {

      get

      {

        return startColor;

      }

      set

      {

        startColor = value;

        if (baseBackground != null && ShowGradient)

        {

          baseBackground.Dispose();

          baseBackground = null;

        }

        Invalidate();

      }

    }

 

    [

    Category("渐变"),

    Description("指定渐变的结束颜色")

    ]

    public Color EndColor

    {

      get

      {

        return endColor;

      }

      set

      {

        endColor = value;

        if (baseBackground != null && ShowGradient)

        {

          baseBackground.Dispose();

          baseBackground = null;

        }

        Invalidate();

      }

    }

 

 

    [Description("当在设计器中更改属性时实现属性的序列化(持久性)")]

    public bool ShouldSerializeStartColor()

    {

      return !(startColor == Color.Wheat);

    }

 

        

    public bool ShouldSerializeEndColor()

    {

      return !(endColor == Color.LimeGreen);

    }

 

 

    

    

    

    protected override void OnBackColorChanged(EventArgs e)

    {

      base.OnBackColorChanged(e);

      if ((baseBackground != null) && (!ShowGradient))

      {

        baseBackground.Dispose();

        baseBackground = null;

      }

    }

 

    protected override void OnTextChanged(EventArgs e)

    {

      base.OnTextChanged(e);

      if ((baseBackground != null) && (!ShowGradient))

      {

        baseBackground.Dispose();

        baseBackground = null;

      }

    }

 

    protected override void OnBackgroundImageChanged(EventArgs e)

    {

      base.OnBackgroundImageChanged(e);

      if ((baseBackground != null) && (!ShowGradient))

      {

        baseBackground.Dispose();

        baseBackground = null;

      }

    }

 

    

    protected override void OnResize(EventArgs e)

    {

      base.OnResize(e);

      if (baseBackground != null)

      {

        baseBackground.Dispose();

        baseBackground = null;

      }

    }

 

    

    

 

 

  }

}

 




相关文章

相关软件