Csharp/C Sharp by API/System.Drawing.Drawing2D/PathGradientBrush

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

new PathGradientBrush(GraphicsPath path)

  
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
public class Form1 : Form
{
  public Form1() {
        InitializeComponent();
  }
  private void Form1_Paint(object sender, PaintEventArgs e)
  {
      GraphicsPath path = new GraphicsPath();
      int size = 150;
      path.AddEllipse(10, 10, size, size);
      
      PathGradientBrush brush = new PathGradientBrush(path);
      brush.WrapMode = WrapMode.Tile;
      brush.SurroundColors = new Color[] { Color.White };
      brush.CenterColor = Color.Violet;
      e.Graphics.FillRectangle(brush, 10, 10, size, size);
      
      path.Dispose();
      brush.Dispose();
  }
  private void InitializeComponent()
  {
    this.SuspendLayout();
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Name = "Form1";
    this.Text = "Alpha Blending";
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    this.ResumeLayout(false);
  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}


new PathGradientBrush(Path.PathPoints, WrapMode.Tile);

  
        
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace GradientWrap_c
{
    public class GradientWrap : System.Windows.Forms.Form
    {
        private System.ruponentModel.Container components = null;
        public GradientWrap()
        {
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(292, 273);
      this.Name = "GradientWrap";
      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
      this.Text = "GradientWrap";
      this.Load += new System.EventHandler(this.GradientWrap_Load);
        }
        static void Main() 
        {
            Application.Run(new GradientWrap());
        }
    private void GradientWrap_Load(object sender, System.EventArgs e)
    {
    
    }
    protected override void OnPaint( PaintEventArgs e )
    {
      GraphicsPath Path = new GraphicsPath();
      Rectangle R = new Rectangle(10, 10, 50, 50);
      e.Graphics.DrawRectangle(Pens.Black,R);
      Path.AddRectangle(R);
      
//      PathGradientBrush B = new PathGradientBrush(Path.PathPoints); 
      PathGradientBrush B = new PathGradientBrush(Path.PathPoints, 
        WrapMode.Tile);
      Color[] c = { Color.Blue, Color.Aqua, Color.Red };
      B.CenterColor = Color.White;
      B.SurroundColors = c;
      //Small circle inside gradient path
      e.Graphics.FillEllipse(B, 15, 15, 30, 30);
      //Large circle outside gradient path
      e.Graphics.FillEllipse(B, 50, 50, 150, 150);
    }
    }
}


PathGradientBrush.CenterColor

  

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        GraphicsPath gp = new GraphicsPath();
        gp.AddLine(10, 10, 110, 15);
        gp.AddLine(110, 15, 100, 96);
        gp.AddLine(100, 96, 15, 110);
        gp.CloseFigure();
        g.FillRectangle(Brushes.White, this.ClientRectangle);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        PathGradientBrush pgb = new PathGradientBrush(gp);
        pgb.CenterColor = Color.White;
        pgb.SurroundColors = new Color[] { Color.Blue };
        g.FillPath(pgb, gp);
        g.DrawPath(Pens.Black, gp);
        pgb.Dispose();
        gp.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}


PathGradientBrush.CenterPoint

  
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class BouncingGradientBrushBall : Form {
    public static void Main() {
        Application.Run(new BouncingGradientBrushBall());
    }
    public BouncingGradientBrushBall() {
        ResizeRedraw = true;
    }
    protected override void OnPaint(PaintEventArgs pea) {
        GraphicsPath path = new GraphicsPath();
        Rectangle rect = new Rectangle(10, 10, 30, 30);
        path.AddEllipse(rect);
        PathGradientBrush pgbrush = new PathGradientBrush(path);
        pgbrush.CenterPoint = new PointF((rect.Left + rect.Right) / 3,
                                         (rect.Top + rect.Bottom) / 3);
        pgbrush.CenterColor = Color.White;
        pgbrush.SurroundColors = new Color[] { Color.Red };
        pea.Graphics.FillRectangle(pgbrush, rect);
    }
}


PathGradientBrush.SurroundColors

  

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form {
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        GraphicsPath gp = new GraphicsPath();
        gp.AddLine(10, 10, 110, 15);
        gp.AddLine(110, 15, 100, 96);
        gp.AddLine(100, 96, 15, 110);
        gp.CloseFigure();
        g.FillRectangle(Brushes.White, this.ClientRectangle);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        PathGradientBrush pgb = new PathGradientBrush(gp);
        pgb.CenterColor = Color.White;
        pgb.SurroundColors = new Color[] { Color.Blue };
        g.FillPath(pgb, gp);
        g.DrawPath(Pens.Black, gp);
        pgb.Dispose();
        gp.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}