2

我正在尝试绘制具有渐变背景效果的面板。我在面板内有 3 个按钮。纽扣也上漆了。如何仅绘制没有子控件的面板

void pnl_Paint(object sender, PaintEventArgs e)
{
    //Create a diagonal linear gradient with four stops.   
    LinearGradientBrush myLinearGradientBrush =
            new LinearGradientBrush(e.ClipRectangle, 
                                    Color.Red, Color.White,
                                    LinearGradientMode.Horizontal);
    ColorBlend cb = new ColorBlend();

    Color c1 = StringToColor("FFAD5C");
    Color c2 = StringToColor("ffffff");
    Color c3 = StringToColor("FFAD5C");

    cb.Positions = new[] { 0, (float)0.75, 1 };
    cb.Colors = new[] { c1, c2, c3 };
    myLinearGradientBrush.InterpolationColors = cb;
    e.Graphics.FillRectangle(myLinearGradientBrush, e.ClipRectangle);
}
4

0 回答 0