注:brush通过起止坐标来控制重绘范围及方向。比如从上到下渐变时,brush第二个Point参数是左下角坐标。
1 private void PaintGradientBackground(Button btn) 2 { 3 Bitmap newGradientBackImg = new Bitmap(btn.Width, btn.Height); 4 LinearGradientBrush brush = new LinearGradientBrush(new PointF(0, 0), new PointF(0, btn.Height), GlobalParams.UnSelected_TreeTab_Top_Color, GlobalParams.UnSelected_TreeTab_Bottom_Color); 5 Graphics gr = Graphics.FromImage(newGradientBackImg); 6 gr.FillRectangle(brush, new RectangleF(0, 0, btn.Width, btn.Height)); 7 //btn.BackColor = Color.Transparent; 8 btn.BackgroundImage = newGradientBackImg; 9 } 10 11 private void ClearGradientBackground(Button btn) 12 { 13 btn.BackgroundImage = null; 14 }
原文地址:https://www.cnblogs.com/wyp1988/p/9844453.html
时间: 2024-10-25 19:23:36