GDI中颜色渐变 可以用 LinearGradientBrush bbr1 = new LinearGradientBrush(rc, Color.Red, Color.White, LinearGradientMode.Vertical);
他来解决 ,但 这种渐变 是从按钮顶上 一直渐变到最下面 ,
如果 要从最上渐变到中间 再重中间渐变到最下面 ,如何实现?
也就是说 现在要 让按钮最上和最下  都是白的 让中间是红的, 怎么弄?

解决方案 »

  1.   

     Graphics _Graphics = Graphics.FromHwnd(button1.Handle);
                Point _Left1 = new Point(0, 0);
                Point _Left2 = new Point(button1.Width / 2, 0);
                Point _Left3 = new Point(button1.Width / 2, button1.Height);
                Point _Left4 = new Point(0, button1.Height);            Point[] _Point = new Point[] { _Left1, _Left2, _Left3, _Left4 };
                PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipXY);
                _SetBruhs.CenterPoint = new PointF(0, 0);
                _SetBruhs.FocusScales = new PointF(0, button1.Height);
                _SetBruhs.CenterColor = Color.White;
                _SetBruhs.SurroundColors = new Color[] { Color.Red};            _Graphics.FillRectangle(_SetBruhs, new Rectangle(0, 0, button1.Width, button1.Height));
                _Graphics.Dispose();这样看看
      

  2.   

    顶 没直接的函数
    只有这个来模拟PathGradientBrush
      

  3.   

    汗一个,楼主也太懒了。
    看我改的            Graphics _Graphics = Graphics.FromHwnd(button1.Handle);
                Point _Left1 = new Point(0, 0);
                Point _Left2 = new Point(0,button1.Height / 2);
                Point _Left3 = new Point(button1.Width , button1.Height/ 2);
                Point _Left4 = new Point(button1.Width,0);            Point[] _Point = new Point[] { _Left1, _Left2, _Left3, _Left4 };
                PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipXY);
                _SetBruhs.CenterPoint = new PointF(0, 0);
                _SetBruhs.FocusScales = new PointF(button1.Width,0);
                _SetBruhs.CenterColor = Color.White;
                _SetBruhs.SurroundColors = new Color[] { Color.Red };            _Graphics.FillRectangle(_SetBruhs, new Rectangle(0, 0, button1.Width, button1.Height));
                _Graphics.Dispose();