WinForm中按钮等控件的背景渐变色重绘

2021-07-04 19:07

阅读:522

标签:phi   global   back   style   form   坐标   bottom   rom   bitmap   

注: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         }

 

WinForm中按钮等控件的背景渐变色重绘

标签:phi   global   back   style   form   坐标   bottom   rom   bitmap   

原文地址:https://www.cnblogs.com/wyp1988/p/9844453.html


评论


亲,登录后才可以留言!