在的WinForms多色线性渐变 [英] Multi-color linear gradient in WinForms
本文介绍了在的WinForms多色线性渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建的WinForms多色线性渐变? System.Drawing.Drawing2D.LinearGradientBrush只允许两种颜色。
How to create multi-color linear gradient in WinForms? System.Drawing.Drawing2D.LinearGradientBrush allows only two colors.
推荐答案
同样的答案如下:在的WinForms 多多色对角线渐变-Color中的WinForms对角线梯度
same answer as here: Multi-color diagonal gradient in winforms Multi-color diagonal gradient in winforms
这里是一个小例子,你这篇文章的启发
http://www.bobpowell.net/linear.htm(多颜色混合)
here is a little example for you inspired by this article
http://www.bobpowell.net/linear.htm (Multiple colour blends)
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屋!
查看全文