快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

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

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);
  }


 }
}


返回类别: 教程
上一教程: 十天学会ASP.net(3)
下一教程: 多线程填写treeview控件(vb.net)

您可以阅读与"一个自定义LABEL组件的C#源代码"相关的教程:
· 关于自定义事件的一点体会
· ASP.NET连SQL7接口源代码
· 基于组件的.NET软件开发(1)
· 在.NET中实现彩色光标,动画光标和自定义光标
· 如何在asp+ 中使用自定义的pagelet
    微笑服务 优质保证 索取样品