I´m doing an aplicattion where i have WPF forms and winforms. I made a cool background gradient in WPF but i need it to use it in my windows forms too.
I tried with this code but it isnt working. It draws the gradient in windows forms, but its not like the WPF one.
Here is the code for 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>
And here my Winform code(Colors are the same):
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);
}
Hope you guys can help me, i need to solve this very fast, and i dont want to use a image background or to put a WPF control in my winforms..
Thanks for your help!
I’m not sure if this will get it exactly because you didn’t include screenshots of what’s different, but I’ll take a stab:
This looks about right, comparing the XAML designer to my WinForms output (XAML designer left, running WinForms app on right):
