Exploring GDI+ : Using The Brush

by Amr 2/15/2008 5:01:00 PM

Brush HierarchyOne of the core classes in the GDI+ framework built in .Net is the Brush class. There are 5 types of Brushes in .Net that help you to color your objects by lot of variations the five types are as shown in the figure :

 

 

The 5 types as shown are :

SolidBrush Defines a brush of a single color. Brushes are used to fill graphics shapes, such as rectangles, ellipses, pies, polygons, and paths.
HatchBrush Defines a rectangular brush with a hatch style, a foreground color, and a background color.
LinearGradientBrush Encapsulates a Brush with a linear gradient.
PathGradientBrush Encapsulates a Brush object that fills the interior of a GraphicsPath object with a gradient.
TextureBrush Each property of the TextureBrush class is a Brush object that uses an image to fill the interior of a shape.

I have built a simple application that uses and shows the output of each brush, remember that options of each bursh is not limited to my sample, there are much more one can do using these brushes.

solid hatch linearGradient

pathGradient texture

Sample Application Code :

Exploring GDI+ Brushes.zip (13.24 kb)

Currently rated 5.0 by 5 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

GDI+

Related posts

Comments

2/17/2008 2:44:01 PM

Jason Kealey

Although it doesn't really matter in your application, I see you're not Disposing the brushes. Could this lead to a memory leak?

Jason Kealey ca

2/17/2008 6:24:36 PM

Amr

Actually, you are right, Brushes are objects that cause memory leaks and need to be disposed.
They should be used like this :

using(SolidBrush brush = new SolidBrush(Color.Yellow))
{ /* use the brush */ }

Also, for using known Color solid brushes there is a static class named Brushes which has some predefined brushes that can be used as an alternative to not get in the headache of clearing the memory >> which is Brushes.Red
In big applications that should be taken care of.
Thanks for pointing out this.

Amr eg

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

5/16/2008 3:43:48 PM

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Amr Elsehemy Amr Elsehemy
MCSD, MCTS Sql 2005 E-mail me Send mail

Calendar

<<  May 2008  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Creative Commons
Sign in

Sitemeter