Winforms中的多色对角渐变 [英] Multi-color diagonal gradient in winforms
本文介绍了Winforms中的多色对角渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在Winforms中用多色对角渐变填充矩形,如下例所示:
I am trying to fill a rectangle with a multi-color diagonal gradient in winforms that looks like the following example: diagonal gradient I know this is a WPF example, but is it possible to get similar results in winforms?
推荐答案
以下是为您提供的一个小示例
Here is a little example for you
void MainFormPaint(object sender, PaintEventArgs e)
{
LinearGradientBrush br = new LinearGradientBrush(this.ClientRectangle, Color.Black, Color.Black, 0 , false);
ColorBlend cb = new ColorBlend();
cb.Positions = new[] {0, 1/6f, 2/6f, 3/6f, 4/6f, 5/6f, 1};
cb.Colors = new[] {Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet};
br.InterpolationColors= cb;
// rotate
br.RotateTransform(45);
// paint
e.Graphics.FillRectangle(br, this.ClientRectangle);
}
这是结果
希望这会有所帮助
这篇关于Winforms中的多色对角渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文