using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using System.Drawing.Drawing2D ;public enum ControlStyleEnum { XpStyle,CommonStyle }namespace TomTangXpButton {
/// <summary> /// Summary description for UserControl1. /// </summary>
[ToolboxBitmap(@"E:\Documents and Settings\Tom\My Documents\Visual Studio Projects\TomTangXpButton\me.bmp")]
public class TomTangXpButton : System.Windows.Forms.Button {
#region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // TomTangXpButton // this.Name = "TomTangXpButton"; } #endregion
Pts[1]=new Point (Width-Dx,0); Pts[2]=new Point (Width,Dx);
Pts[3]=new Point (Width,Heigth-Dx); Pts[4]=new Point (Width-Dx,Heigth);
Pts[5]=new Point (Dx,Heigth); Pts[6]=new Point (0,Heigth-Dx);
Pts[7]=new Point (0,Dx);
// FillMode newFillMode = FillMode.Winding;
g.DrawPolygon (new Pen (new SolidBrush (DrawColor ),1.0f),Pts);
//g.FillRectangle (new SolidBrush (Color.Transparent ),this.ClientRectangle ); // g.FillPolygon (new SolidBrush (Color.WhiteSmoke ),Pts,newFillMode); // g.DrawPolygon (new Pen (new SolidBrush (Color.DodgerBlue ),1.0f),Pts);
e.Graphics.DrawRectangle (new Pen(new SolidBrush (this.BackColor ),4.0f),this.ClientRectangle ); Color Cf=Color.FromArgb(mColorFromTransparent,mColorFrom); Color Ct=Color.FromArgb (mColorToTransparent,mColorTo);
Brush b=new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle ,Cf,Ct,mLinearGradientMode); Rectangle Rt=new Rectangle (new Point (3,3),new Size (this.Width -6,this.Height -6));
http://www.codeproject.com/cs/miscctrl/first_control.asp
做一个VS.NET界面的组件出来吧,让大家用一下:)
<Visual Basic.NET和Visual C#.NET面向对象程序设计>
http://www.china-pub.com/computers/common/info.asp?id=6678
奉送一段原代码,一个我的一个扩展的BUTTON控件:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D ;public enum ControlStyleEnum
{
XpStyle,CommonStyle
}namespace TomTangXpButton
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
[ToolboxBitmap(@"E:\Documents and Settings\Tom\My Documents\Visual Studio Projects\TomTangXpButton\me.bmp")]
public class TomTangXpButton : System.Windows.Forms.Button
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public TomTangXpButton()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
mControlStyle=ControlStyleEnum.XpStyle ;
mLinearGradientMode=LinearGradientMode.Vertical ;
mBorderColor=SystemColors.Desktop;
mShadowColor=Color.DarkGray;
mColorFromTransparent=64;
mColorToTransparent=64;
mColorFrom=Color.White ;
mColorTo=Color.Gray;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// TomTangXpButton
//
this.Name = "TomTangXpButton"; }
#endregion
private void DrawXpStyle(Graphics g,int Width,int Heigth,Color DrawColor)
{
Point [] Pts=new Point [8];
int Dx=3;
Pts[0]=new Point (Dx,0);
Pts[1]=new Point (Width-Dx,0);
Pts[2]=new Point (Width,Dx);
Pts[3]=new Point (Width,Heigth-Dx);
Pts[4]=new Point (Width-Dx,Heigth);
Pts[5]=new Point (Dx,Heigth);
Pts[6]=new Point (0,Heigth-Dx);
Pts[7]=new Point (0,Dx);
// FillMode newFillMode = FillMode.Winding;
g.DrawPolygon (new Pen (new SolidBrush (DrawColor ),1.0f),Pts);
//g.FillRectangle (new SolidBrush (Color.Transparent ),this.ClientRectangle );
// g.FillPolygon (new SolidBrush (Color.WhiteSmoke ),Pts,newFillMode);
// g.DrawPolygon (new Pen (new SolidBrush (Color.DodgerBlue ),1.0f),Pts);
}
private void DrawXpStyle1(Graphics g,int Width,int Heigth,int MoveDx,Color DrawColor)
{
Point [] Pts=new Point [8];
int Dx=1;
Pts[0]=new Point (Dx+MoveDx,0+MoveDx);
Pts[1]=new Point (Width-Dx-MoveDx,0+MoveDx);
Pts[2]=new Point (Width-MoveDx,Dx+MoveDx);
Pts[3]=new Point (Width-MoveDx,Heigth-Dx-MoveDx);
Pts[4]=new Point (Width-Dx-MoveDx,Heigth-MoveDx);
Pts[5]=new Point (Dx+MoveDx,Heigth-MoveDx);
Pts[6]=new Point (0+MoveDx,Heigth-Dx-MoveDx);
Pts[7]=new Point (0+MoveDx,Dx+MoveDx);
// FillMode newFillMode = FillMode.Winding;
g.DrawPolygon (new Pen (new SolidBrush (DrawColor),3.0f),Pts);
// g.FillRectangle (new SolidBrush (this.BackColor ),this.ClientRectangle );
// g.FillPolygon (new SolidBrush (Color.WhiteSmoke ),Pts,newFillMode);
// g.DrawPolygon (new Pen (new SolidBrush (Color.DodgerBlue ),1.0f),Pts);
}
private Color mColorFrom;
private Color mColorTo;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
if ( mControlStyle==ControlStyleEnum.XpStyle )
{
e.Graphics.DrawRectangle (new Pen(new SolidBrush (this.BackColor ),4.0f),this.ClientRectangle );
Color Cf=Color.FromArgb(mColorFromTransparent,mColorFrom);
Color Ct=Color.FromArgb (mColorToTransparent,mColorTo);
Brush b=new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle ,Cf,Ct,mLinearGradientMode);
Rectangle Rt=new Rectangle (new Point (3,3),new Size (this.Width -6,this.Height -6));
e.Graphics.FillRectangle (b,Rt);
DrawXpStyle1(e.Graphics ,this.Width -1,this.Height -1,1,mShadowColor );
DrawXpStyle(e.Graphics ,this.Width-1 ,this.Height-1,mBorderColor );
b.Dispose ();
}
}
//FROM 颜色
public Color ColorFrom
{
get
{
return mColorFrom;
}
set
{
mColorFrom=value;
Invalidate();
}
}
// TO 颜色
public Color ColorTo
{
get
{
return mColorTo;
}
set
{
mColorTo=value;
Invalidate();
}
}
private ControlStyleEnum mControlStyle;
private int mColorFromTransparent;
private int mColorToTransparent;
private Color mBorderColor;
private Color mShadowColor;
//FROM 颜色透明
public int ColorFromTransparent
{
get
{
return mColorFromTransparent;
}
set
{
mColorFromTransparent=value;
Invalidate();
}
}
//TO颜色透明
public int ColorToTransparent
{
get
{
return mColorToTransparent;
}
set
{
mColorToTransparent=value;
Invalidate();
}
}
public ControlStyleEnum ControlStyle
{
get
{
return mControlStyle;
}
set
{
mControlStyle=value;
Invalidate();
}
}
public Color BorderColor
{
get
{
return mBorderColor;
}
set
{
mBorderColor=value;
Invalidate();
}
}
public Color ShadowColor
{
get
{
return mShadowColor;
}
set
{
mShadowColor=value;
Invalidate();
}
}
private LinearGradientMode mLinearGradientMode=LinearGradientMode.ForwardDiagonal ;
public LinearGradientMode DrawLinearGradientMode
{
get
{
return mLinearGradientMode;
} set
{
mLinearGradientMode=value;
Invalidate();
} }
}
}
希望对你有帮助:)
http://madn.microsoft.com/net/
2. .NETBOOKS网站搜集了所有.NET书籍的资料让你一览无遗。
http://www.gotdone.com/quickstart/aspplus
3. 另外,从基础到高级的 相关课程,可以从以下网站查询课程内容:
http://edu.uuu.com.tw