Mega Code Archive

 
Categories / C# Tutorial / 2D Graphics
 

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