背景图片上面有按钮,我把按钮设置成透明,但是背景按钮图片上的圆角体现不出来.

解决方案 »

  1.   

    用ImageButton,Button的形狀是由圖片決定的
      

  2.   

    好像没有 ImageButton,异型按钮怎么做,我还不会画呢?
      

  3.   

    自定义一个控件,继承与Button,然后把下面的方法加进去,在InitializeComponent();之后调用ChangeRegion方法。
    下面我的方法是去掉所有白色的部分,你应该用透明色代替我的白色,这样就可以根据这个控件的背景图的不透明部分创建任意形状的按钮了private void ChangeRegion()
            {
                #region 这段代码是为了根据颜色创建平滑的圆角矩形控件,也可以使用OnPaint里面注释掉的代码创建圆角矩形控件,但是不够平滑
                //创建一个空的临时Region
                Region thisRegion = new Region();
                thisRegion.MakeEmpty();            //创建一个高度为1的矩形
                Rectangle curRect = new Rectangle();
                curRect.Height = 1;            int x = 0, y = 0;
                bool isWhite = false;
                Color curColor;            //获取当前窗体的图像
                Bitmap bt = new Bitmap(this.Width, this.Height);
              this.DrawToBitmap(bt, new Rectangle(0, 0, this.Width, this.Height));
                //逐像素扫描这个图片,找出白色部分区域并合并起来。
                for (y = 0; y < this.Height; ++y)
                {
                    isWhite = true;
                    for (x = 0; x < this.Width; ++x)
                    {
                        curColor = bt.GetPixel(x, y);
                        if (curColor.ToArgb() == Color.White.ToArgb() || x == this.Width - 1)//如果遇到透明色或行尾
                        {
                            if (isWhite == false)//退出有效区
                            {
                                curRect.Width = x - curRect.X;
                                thisRegion.Union(curRect);
                            }
                        }
                        else//非透明色
                        {
                            if (isWhite == true)//得到一行里面的第一个非白色点,作为要加入Region的矩形的起点。进入有效区
                            {
                                curRect.X = x;
                                curRect.Y = y;
                            }
                        }//if curColor
                        isWhite = curColor.ToArgb() == Color.White.ToArgb();
                    }//for x
                }//for y            this.Region = thisRegion;
                #endregion
            }