.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Different HatchBrushes in C#

Posted By:Abhisek Panda       Posted Date: November 25, 2009    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Different HatchBrushes in C#:-

        The System.Drawing.Drawing2D namespace defines a Brush-derived type named HatchBrush . This allows us to fill a region using a number of predefined patterns, presented by the HatchStyle enumeration.

     When you are constructing a HatchBrush, we have to specify the foreground and background colors to use during the filling operation. The following code demonstrates how to work with different HatchBrushes(Horizontal, Vertical, ForwardDiagonal and BackwardDiagonal).There are also a huge no. of brushes available. Just create a new window application in C# and add the following code to the form's Paint event handler.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace BrushStyles
public partial class MainForm : Form
public MainForm()
private void MainForm_Paint(object sender, PaintEventArgs e)
Graphics g = e.Graphics;
int yOffSet = 10;
// Get all members of the HatchStyle enum.
Array obj = Enum.GetValues(typeof(HatchStyle));
// Draw an oval with first 5 HatchStyle values.
for (int x = 0; x < 5; x++)
// Configure Brush.
HatchStyle hs = (HatchStyle)obj.GetValue(x);
HatchBrush hBrush = new HatchBrush(hs,
Color.White, Color.Black);
// Print name of HatchStyle enum.
g.DrawString(hs.ToString(), new Font("Times New Roman", 10),
Brushes.Black, 0, yOffSet);
// Fill a rectangle with the correct brush.
g.FillEllipse(hBrush, 150, yOffSet, 200, 25);
yOffSet += 40;
When you run the program it will show you the different brushes inside an oval with there names in the left side.


Further Readings:


    No response found. Be the first to respond this post

    Post Comment

    You must Sign In To post reply
    Find More code samples in C#, ASP.Net, Vb.Net and more Here

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend