怎么写一个圆形按钮控件啊,或者怎么把Button 改成圆的

解决方案 »

  1.   

    Button 有这属性吗,怎么找不到啊
      

  2.   

    silverlight中的button,想要什么形状都可以,楼主不妨可以试试……
      

  3.   

    html中:做一个圆的图片:<input type ="button" src = "img.jpg"/>
    c#中:System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
             path.AddEllipse(this.btn_circle.ClientRectangle);
             this.btn_circle.Region = new Region(path); 
      

  4.   

    Windows Forms中怎么用啊
      

  5.   

    写成一个方法加载的调用一次. 按钮大小改变的事件里也要调用.  public void EllipseBtn(Button btn)
            {
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                int w = btn.Width > btn.Height ? btn.Height : btn.Width;
                path.AddEllipse(1, 1, w, w);
                Region region = new Region(path);
                btn.Region = region;
            }
      

  6.   

    制作异形窗体或控件的思路一般都是想办法生成一个region,然后设置给指定的窗口或控件。生成region的方法有很多,最常用的就是从一幅图片生成,把该图片中的透明色部分“抠”掉,剩下的部分作为一个region。设置窗口或控件的region可以用SetWindowRgn API,不过.NET framework封装了这个操作,在C#中只要对窗口或控件的Region属性赋值就可以了。下面我就把我在C#中实现异形窗体的核心代码贴出来给大家看看.
    首先,是一个根据Bitmap对象生成Region的方法:/// <summary>/// 取得一个图片中非透明色部分的区域。/// </summary>/// <param name="Picture">取其区域的图片。</param>/// <param name="TransparentColor">透明色。</param>/// <returns>图片中非透明色部分的区域</returns>private Region BmpRgn(Bitmap Picture, Color TransparentColor){     int nWidth = Picture.Width;     int nHeight = Picture.Height;     Region rgn = new Region();     rgn.MakeEmpty();     bool isTransRgn;//前一个点是否在透明区     Color curColor;//当前点的颜色     Rectangle curRect = new Rectangle();     curRect.Height = 1;     int x = 0, y = 0;     //逐像素扫描这个图片,找出非透明色部分区域并合并起来。     for(y = 0; y < nHeight; ++y)     {         isTransRgn = true;         for (x = 0; x < nWidth; ++x)         {              curColor = Picture.GetPixel(x,y);              if(curColor == TransparentColor || x == nWidth - 1)//如果遇到透明色或行尾                   {                       if(isTransRgn == false)//退出有效区                       {                            curRect.Width = x - curRect.X;                            rgn.Union(curRect);                       }                   }                   else//非透明色                   {                       if(isTransRgn == true)//进入有效区                       {                            curRect.X = x;                            curRect.Y = y;                       }                   }//if curColor                   isTransRgn = curColor == TransparentColor;                  }//for x         }//for y         return rgn;     }
    原理很简单,就是对该图片逐行扫描,在每一行中把那些非透明色的矩形(只有一个像素高)合并(union)到一个Region对象中,当扫描完整个图片,得到的也就是我们想要的Region了。这种算法在很多文章里都有介绍的。有了region,下面就简单了:this.Region = BmpRgn(new Bitmap("d:\\a.bmp"), Color.FromArgb(0, 0, 0));上面的代码就是把d:\a.bmp的轮廓作为主窗口的region的,假设该图片的背景黑色(Color.FromArgb(0, 0, 0))。其实不光是Form,任何控件都可以用这个方法设置Region,制作出异形控件。