2
我正在做一個適用於WPF窗體和winforms的應用程序。我在WPF中創建了一個很酷的背景漸變,但我也需要它在我的窗體中使用它。 我試着用這段代碼,但它不工作。它在Windows窗體中繪製漸變,但不像WPF那樣。使Windows窗體中的WPF漸變
這裏是WPF代碼:
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFCFEFF" Offset="0" />
<GradientStop Color="#FFA6BAD0" Offset="1" />
<GradientStop Color="#FFE4EFF7" Offset="0.317" />
<GradientStop Color="#FFC8D4E3" Offset="0.585" />
<GradientStop Color="#FFB1C6D7" Offset="0.797" />
<GradientStop Color="#FFF7FBFD" Offset="0.146" />
<GradientStop Color="#FFD9E4EE" Offset="0.439" />
</LinearGradientBrush>
</Grid.Background>
在這裏,我的WinForm的代碼(顏色相同):
public void Form_Background(object sender, PaintEventArgs e)
{
Color c1 = Color.FromArgb(255, 252, 254, 255);
Color c2 = Color.FromArgb(255, 247, 251, 253);
Color c3 = Color.FromArgb(255, 228, 239, 247);
Color c4 = Color.FromArgb(255, 217, 228, 238);
Color c5 = Color.FromArgb(255, 200, 212, 217);
Color c6 = Color.FromArgb(255, 177, 198, 215);
Color c7 = Color.FromArgb(255, 166, 186, 208);
LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 0, false);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] { 0, (float)0.146, (float)0.317, (float)0.439, (float)0.585, (float)0.797 , 1};
cb.Colors = new[] { c1, c2, c3, c4, c5, c6, c7 };
br.InterpolationColors = cb;
// rotate
br.RotateTransform(90);
// paint
e.Graphics.FillRectangle(br, this.ClientRectangle);
}
希望你們能幫助我,我需要非常解決這個快,我不想要使用圖像背景或將WPF控件放入我的Winforms中。
感謝您的幫助!
非常感謝你!工作! – Andres