C#中的普通按钮都是方形的啊、
我想做个圆形的按钮。。不知道各位大大有什么好的技巧
最好带点代码。
我是菜鸟哈
谢谢!

解决方案 »

  1.   

    用PictureBox是最简单的,想自己画也行,下面是一个RoundButton的例子:http://www.codeproject.com/KB/buttons/RoundButton_csharp.aspx
      

  2.   

    1、用PIctuerBox也行   
        
     2、用VB写的代码: RoundRectFrame   Picture1,   30,   30   
        
      '创建圆角矩形   
      Public   Sub   RoundRectFrame(objEllipse   As   Object,   Optional   ByVal   x3   As   Long   =   8   _   
                      ,   Optional   ByVal   y3   As   Long   =   8)   
              Dim   lngW   As   Long,   lngH   As   Long   
              Dim   hWndRet   As   Long   
                
              lngW   =   objEllipse.Width   \   Screen.TwipsPerPixelX   
              lngH   =   objEllipse.Height   \   Screen.TwipsPerPixelY   
                
              hWndRet   =   CreateRoundRectRgn(0,   0,   lngW,   lngH,   x3,   y3)   
              Call   SetWindowRgn(objEllipse.hWnd,   hWndRet,   True)   
                
      End   Sub
    3、用c#代码做的
       using   System;   
      using   System.ComponentModel;   
      using   System.Collections;   
      using   System.Diagnostics;   
      using   System.Drawing;   
      using   System.Drawing.Drawing2D;   
      using   System.Windows.Forms;   
        
        
      namespace   WindowsApplication1   
      {   
      ///   <summary>   
      ///   Summary   description   for   cilpButton.   
      ///   </summary>   
      public   class   cilpButton   :   System.Windows.Forms.Button   
      {   
      protected   override   void   OnPaint(System.Windows.Forms.PaintEventArgs   e)   
      {   
      base.OnPaint(e);   
      System.Drawing.Drawing2D.GraphicsPath   path   =   new   System.Drawing.Drawing2D.GraphicsPath();   
      path.AddEllipse(0,0,   this.Width,   this.Height);   
      this.Region   =   new   Region(path);   
      }   
        
      protected   override   void   OnMouseEnter(EventArgs   e)   
      {   
      Graphics   g   =   this.CreateGraphics();   
      g.DrawEllipse(new   Pen(Color.Red),   0,   0   ,   this.Width,   this.Height);   
      g.Dispose();   
      }   
      protected   override   void   OnMouseLeave(EventArgs   e)   
      {   
      Graphics   g   =   this.CreateGraphics();   
      g.DrawEllipse(new   Pen(this.BackColor),   0,   0   ,   this.Width,   this.Height);   
      g.Dispose();   
      }   
          
      protected   override   void   OnPaintBackground(PaintEventArgs   pevent)   
      {   
      Pen   pen   =   new   Pen(this.BackColor);   
      Graphics   g   =   this.CreateGraphics();   
      g.Clear(Color.Goldenrod);   
      g.FillEllipse(Brushes.DarkKhaki,   new   Rectangle(0,0,   this.Width,   this.Height));   
      }   
        
      protected   override   void   OnMouseDown(MouseEventArgs   e)   
      {   
      OnPaintBackground(null);   
      }   
      protected   override   void   OnMouseUp(MouseEventArgs   e)   
      {   
      this.OnClick(e);//响应click事件.   
      }   
      }   
      }  
    试试,自己修改修改,大致就是这么个思想,建议用Picturebox简单
      

  3.   

    1、用PIctuerBox也行   
        
     2、用VB写的代码: RoundRectFrame   Picture1,   30,   30   
        
      '创建圆角矩形   
      Public   Sub   RoundRectFrame(objEllipse   As   Object,   Optional   ByVal   x3   As   Long   =   8   _   
                      ,   Optional   ByVal   y3   As   Long   =   8)   
              Dim   lngW   As   Long,   lngH   As   Long   
              Dim   hWndRet   As   Long   
                
              lngW   =   objEllipse.Width   \   Screen.TwipsPerPixelX   
              lngH   =   objEllipse.Height   \   Screen.TwipsPerPixelY   
                
              hWndRet   =   CreateRoundRectRgn(0,   0,   lngW,   lngH,   x3,   y3)   
              Call   SetWindowRgn(objEllipse.hWnd,   hWndRet,   True)   
                
      End   Sub
    3、用c#代码做的
       using   System;   
      using   System.ComponentModel;   
      using   System.Collections;   
      using   System.Diagnostics;   
      using   System.Drawing;   
      using   System.Drawing.Drawing2D;   
      using   System.Windows.Forms;   
        
        
      namespace   WindowsApplication1   
      {   
      ///   <summary>   
      ///   Summary   description   for   cilpButton.   
      ///   </summary>   
      public   class   cilpButton   :   System.Windows.Forms.Button   
      {   
      protected   override   void   OnPaint(System.Windows.Forms.PaintEventArgs   e)   
      {   
      base.OnPaint(e);   
      System.Drawing.Drawing2D.GraphicsPath   path   =   new   System.Drawing.Drawing2D.GraphicsPath();   
      path.AddEllipse(0,0,   this.Width,   this.Height);   
      this.Region   =   new   Region(path);   
      }   
        
      protected   override   void   OnMouseEnter(EventArgs   e)   
      {   
      Graphics   g   =   this.CreateGraphics();   
      g.DrawEllipse(new   Pen(Color.Red),   0,   0   ,   this.Width,   this.Height);   
      g.Dispose();   
      }   
      protected   override   void   OnMouseLeave(EventArgs   e)   
      {   
      Graphics   g   =   this.CreateGraphics();   
      g.DrawEllipse(new   Pen(this.BackColor),   0,   0   ,   this.Width,   this.Height);   
      g.Dispose();   
      }   
          
      protected   override   void   OnPaintBackground(PaintEventArgs   pevent)   
      {   
      Pen   pen   =   new   Pen(this.BackColor);   
      Graphics   g   =   this.CreateGraphics();   
      g.Clear(Color.Goldenrod);   
      g.FillEllipse(Brushes.DarkKhaki,   new   Rectangle(0,0,   this.Width,   this.Height));   
      }   
        
      protected   override   void   OnMouseDown(MouseEventArgs   e)   
      {   
      OnPaintBackground(null);   
      }   
      protected   override   void   OnMouseUp(MouseEventArgs   e)   
      {   
      this.OnClick(e);//响应click事件.   
      }   
      }   
      }  
    试试,自己修改修改,大致就是这么个思想,建议用Picturebox简单
      

  4.   

    重写Button的Paint方法就行了。//下面的方法是重新写了Button的Paint方法,将会绘制一个圆角按钮
    private void roundButton_Paint(object sender, 
        System.Windows.Forms.PaintEventArgs e)
    {    System.Drawing.Drawing2D.GraphicsPath buttonPath = 
            new System.Drawing.Drawing2D.GraphicsPath();    // Set a new rectangle to the same size as the button's 
        // ClientRectangle property.
        System.Drawing.Rectangle newRectangle = roundButton.ClientRectangle;    // Decrease the size of the rectangle.
        newRectangle.Inflate(-10, -10);
        
        // Draw the button's border.
        e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle);    // Increase the size of the rectangle to include the border.
        newRectangle.Inflate( 1,  1);    // Create a circle within the new rectangle.
        buttonPath.AddEllipse(newRectangle);
                
        //设置按钮的Region.
        roundButton.Region = new System.Drawing.Region(buttonPath);}
      

  5.   

    改变控件的 Region 就可以了
      

  6.   

    GraphicsPath   oPath   =   new   GraphicsPath();   
    oPath.AddEllipse(this.ClientRectangle);   
    重绘按钮
    http://www.codeproject.com/KB/buttons/TransButtonNetDemo.aspx
      

  7.   

    WPF 技术很容易实现,不过.NET3.0一下版本不可以,5L的方法是最好的,不过需要点GDI方面的知识