动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 一个自定义LABEL组件的C#源代码

作者:郁郁小蝎 来源:中国站长学院 
阅读 数 60 人次 , 2006-2-15 14:30:00 

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 first 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 after use
  //   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 after use
   using (LinearGradientBrush lgb = new LinearGradientBrush(rect, gradientColorOne,gradientColorTwo,lgm))
    gfx.FillRectangle(lgb,rect);
   
   ControlPaint.DrawBorder3D(gfx,rect,b3dstyle);
  }


 }
}

  
 本文TagsC#  组件  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:LCS问题算法之VB.net版
· 下一篇:在C#中使用XML指南之读取XML
· ASP.NET编程中的十大技巧
· VS.NET: 通过Web服务瞄准电子商务
· ASP.NET图象处理详解
· 一个FTP客户端的C#代码
· SQL命令中DateTime格式参考


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077