我记得原来vb中有API函数可以这样的,C#中应该可以的,你到www.allapi.net上看看,有没有(英文)。

解决方案 »

  1.   

    参考:
    仿Windows Media Player的播放器
    http://www.dapha.net/down/show.asp?classid=2
      

  2.   

    GraphicsPath
    Region
    两个类共同使用,可以搞定!
      

  3.   

    通过继承修改
    我做了一个修改的例子class;
    在使用的时候直接声明就行,主要是通过重载OnPaint事件修改(用GraphicDraw)
    using System;
    using System.Drawing;
    using System.Windows;
    using System.Windows.Forms; namespace Buttons
    {
    /// <summary>
    /// Summary description for MyButton.
    /// </summary>
    public class MyButton:System.Windows.Forms.Button
    {
    private bool mouseDown=false;    //设置鼠标位置状态按下
    private bool mouseHover=false;   //设置鼠标位置状态悬停
    public MyButton()
    {
    //
    // TODO: Add constructor logic here
    //
    // BackColor=System.Drawing.Color.Blue;  //设置背景色为蓝色
    // FlatStyle=System.Windows.Forms.FlatStyle.Flat;
    // Font=System.Windows.Forms.Control.DefaultFont;
    // ForeColor=System.Drawing.Color.White;
                MouseDown+=new MouseEventHandler(OnMouseDown);     //重写鼠标按下事件
                MouseUp+=new MouseEventHandler(OnMouseUp);         //重写鼠标弹上事件
    MouseEnter+=new EventHandler(OnMouseEnter);        //重写鼠标焦点事件
    MouseLeave+=new EventHandler(OnMouseLeave);        //重写鼠标悬停事件
    }
    protected override void OnPaint(PaintEventArgs pe)     //重载OnPaint事件
    {
    pe.Graphics.Clear(this.Parent.BackColor);  
    pe.Graphics.FillEllipse(new SolidBrush(Parent.BackColor),pe.ClipRectangle);    //填充一个矩形的形状来展示按钮
    if (Enabled==false)   //没有被灰掉
    {
    DrawDisableButton(pe.Graphics);
    WriteText(pe.Graphics);  //添加按钮文字
    }
    else if (mouseDown)    //当鼠标按下
    {
    DrawMouseDownButton(pe.Graphics);
    WriteTextL(pe.Graphics);
    }
    else if (mouseHover)  //当鼠标悬停
    {
    DrawMouseHoverButton(pe.Graphics);
    WriteText(pe.Graphics);  //添加按钮文字
    }
    else if (Focused)    //当按钮得到焦点
    {
    DrawContainFocusButton(pe.Graphics);
    WriteText(pe.Graphics);  //添加按钮文字
    }
    else      //当处在正常条件下
    {
    DrawNomalButton(pe.Graphics);
    WriteText(pe.Graphics);  //添加按钮文字
    }

    }
    private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)  //当鼠标按下
    {
                 mouseDown=true;
    }
    private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
                 mouseDown=false;
                 PaintEventArgs pe= new PaintEventArgs(CreateGraphics(),ClientRectangle);  //重画矩形按钮
                 OnPaint(pe);
    }
    private void OnMouseEnter(object sender, System.EventArgs e)
    {
    mouseHover=true;
    PaintEventArgs pe= new PaintEventArgs(CreateGraphics(),ClientRectangle);  //重画矩形按钮
    OnPaint(pe);            
    }
    private void OnMouseLeave(object sender, System.EventArgs e)
    {
    mouseHover=false;
    PaintEventArgs pe= new PaintEventArgs(CreateGraphics(),ClientRectangle);  //重画矩形按钮
    OnPaint(pe);  
    }
    private void DrawBorder(Graphics g,int state)
    {
    //int x=0,y=0;     //填充矩形位置
    if (state==1)
    {
    // Pen p=new Pen(SystemColors.ControlLightLight,2); }
    else if (state==2)   //当鼠标悬停的时候
    { }
    else if (state==3)
    { }
    else if (state==5)
    { }
    else if (state==6)   //当按钮灰掉的时候,重画按钮
    {
    // Pen p=new Pen(Color.FromArgb(161,161,161) ,1); }
    else   //当按钮为普通状态的时候
    {
    // Pen p=new Pen(Color.FromArgb(161,161,161) ,1); }
    }
    private void DrawNomalButton(Graphics g)
    {
                DrawBorder(g,1);
                PaintBack(g,SystemColors.ControlLightLight);
    }
    private void DrawMouseHoverButton(Graphics g)
    {
    DrawBorder(g,2);
    PaintBack(g,Color.SkyBlue);     //当鼠标悬停的时候背景变篮
    }
    private void DrawMouseDownButton(Graphics g)
    {
    DrawBorder(g,3);
    PaintBack(g,SystemColors.ControlLightLight);
    }
    private void DrawDisableButton(Graphics g)
    {
    DrawBorder(g,4);
    PaintBack(g,SystemColors.ControlLightLight); 
    } private void DrawContainFocusButton(Graphics g)
    {
    DrawBorder(g,5);
    PaintBack(g,SystemColors.ControlLightLight);
    }
    private void PaintBack(Graphics g,Color c)   //融合背景色
    {
    g.FillEllipse(new SolidBrush(c),3,3,Width-6,Height-6);   //用椭圆填充背景色3,3,Width-6,Height-6
    }
    private void WriteText(Graphics g)
    {
    int x=0,y=0;
    Size s=g.MeasureString(Text,Font).ToSize();
                x=(Width-s.Width)/2;
    y=(Height-s.Height)/2;
    if (Enabled)    //画文字
    {
    g.DrawString(Text,Font,Brushes.Black,x,y);
    }
    else
    {
                    g.DrawString(Text,Font,Brushes.Gray,x,y);
    }
    }
    private void WriteTextL(Graphics g)
    {
    int x=0,y=0;
    Size s=g.MeasureString(Text,Font).ToSize();
    x=(Width-s.Width)/2;
    y=(Height-s.Height)/2;
    if (Enabled)    //画文字
    {
    g.DrawString(Text,Font,Brushes.Black,x+1,y+1);
    }
    else
    {
    g.DrawString(Text,Font,Brushes.Gray,x+1,y+1);
    }
    }
    }
    }