Panel的绘画事件还绘制了面板中的控件

时间:2013-05-27 12:43:55

标签: c# winforms panel

我正在尝试绘制具有渐变背景效果的面板。我面板内有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);
}

0 个答案:

没有答案