22

WinFormsで多色線形グラデーションを作成するには? System.Drawing.Drawing2D.LinearGradientBrush では 2 色のみ使用できます。

4

2 に答える 2

62

ここと同じ答え: winforms のマルチカラー斜めグラデーション winforms のマルチカラー斜めグラデーション

ここに少し例があります

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);
}

これが結果です

ここに画像の説明を入力

お役に立てれば

于 2011-12-06T20:24:09.403 に答える