【问题标题】:Multi-color diagonal gradient in winforms [duplicate]winforms中的多色对角渐变[重复]
【发布时间】:2011-12-06 15:54:17
【问题描述】:

我正在尝试在 winforms 中使用多色对角渐变填充矩形,如下例所示:diagonal gradient 我知道这是一个 WPF 示例,但是是否有可能在 winforms 中获得类似的结果?

【问题讨论】:

    标签: c# winforms gradient


    【解决方案1】:

    给你一个小例子

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

    这是结果

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      是的,您可以在带有 GDI+ 的 winforms 中使用LinearGradientBrush 执行此操作。这是一个代码示例:http://www.codeproject.com/KB/GDI-plus/gdiplusbrushes.aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-30
        • 1970-01-01
        • 2010-12-26
        • 2016-12-13
        • 2017-01-28
        • 2011-05-10
        相关资源
        最近更新 更多