Csharp/CSharp Tutorial/2D/HatchBrush — различия между версиями

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

Текущая версия на 12:18, 26 мая 2010

Create HatchBrush: style and color

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class BrushHatcHorizontalBrick : System.Windows.Forms.Form
{
  public BrushHatcHorizontalBrick()
  {
    this.BackColor = System.Drawing.Color.White;
    this.ClientSize = new System.Drawing.Size(400, 400);
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.BrushHatcHorizontalBrick_Paint);
  }
  static void Main() 
  {
    Application.Run(new BrushHatcHorizontalBrick());
  }
  private void BrushHatcHorizontalBrick_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics g = e.Graphics;
    Brush brHatch = new HatchBrush(HatchStyle.HorizontalBrick,Color.Red, Color.Yellow);
    g.FillEllipse(brHatch, 200, 200, 150, 190);
  }
}

Hatch Brush Array (HatchStyle minimum and maximum values)

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
   
class HatchBrushArray: Form
{
     const int iSize = 32, iMargin = 8;
     const int iMin = 0, iMax = 52;  // 
   
     public static void Main()
     {
          Application.Run(new HatchBrushArray());
     }
     public HatchBrushArray()
     {
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }       
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          for (HatchStyle hs = (HatchStyle)iMin; hs <= (HatchStyle)iMax; hs++)
          {
               HatchBrush hbrush = 
                              new HatchBrush(hs, Color.White, Color.Black);
               int y = (int)hs / 8;
               int x = (int)hs % 8;
   
               grfx.FillRectangle(hbrush, iMargin + x * (iMargin + iSize), 
                                          iMargin + y * (iMargin + iSize), 
                                          iSize, iSize);
          }
     }
}

HatchBrush Style

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class BrushStyleForm : System.Windows.Forms.Form
{
  private System.ruponentModel.Container components;
  public BrushStyleForm()
  {
    InitializeComponent();
  }
  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }
  private void InitializeComponent()
  {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new BrushStyleForm());
  }
  private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
    Graphics g = e.Graphics;
    int yOffSet = 10;
    Array obj = Enum.GetValues(typeof(HatchStyle));
    for(int x = 0; x < 10; x++)
    {
      HatchStyle temp = (HatchStyle)obj.GetValue(x);
      HatchBrush theBrush = new HatchBrush(temp, Color.White, Color.Black);      
      
      g.DrawString(temp.ToString(), new Font("Times New Roman", 10), new SolidBrush(Color.Black), 0, yOffSet);
      g. FillEllipse(theBrush, 150, yOffSet, 200, 25);
      yOffSet += 40;
    }
  }
}

HatchStyle.LargeConfetti

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        HatchBrush hb = new HatchBrush(HatchStyle.LargeConfetti,Color.AntiqueWhite, Color.Blue);
        g.FillEllipse(hb, 30, 30, Width - 50, 30);

    }
}

HatchStyle.Plaid

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        HatchBrush hb = new HatchBrush(HatchStyle.Plaid, Color.AntiqueWhite, Color.Black);
        g.FillEllipse(hb, 30, 30, Width - 50, 30);
    }
}

HatchStyle.ZigZag

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
public class Form1 : System.Windows.Forms.Form {
    [STAThread]
    static void Main() {
        Application.Run(new Form1());
    }
    protected override void OnPaint(PaintEventArgs e) {
        Graphics g = e.Graphics;
        HatchBrush hb4 = new HatchBrush(HatchStyle.ZigZag, Color.AntiqueWhite, Color.Black);
        g.FillEllipse(hb4, 30, 180, Width - 50, 30);
    }
}

new HatchBrush

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;
        g.FillRectangle(Brushes.White, this.ClientRectangle);
        HatchBrush hb = new HatchBrush(
                 HatchStyle.WideUpwardDiagonal,
                 Color.White,
                 Color.Black);
        Pen hp = new Pen(hb, 8);
        g.DrawRectangle(hp, 15, 15, 70, 70);
        hb.Dispose();
        hp.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}

new HatchBrush(HatchStyle.Cross,Color.White,Color.Black)

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;
    HatchBrush hb = new HatchBrush(
              HatchStyle.Cross,
              Color.White,
              Color.Black);
    g.FillRectangle(hb, this.ClientRectangle);
    hb.Dispose();
    }
    public static void Main() {
        Application.Run(new Form1());
    }
}