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


Top 5 Contributors of the Month
david stephan

Home >> Articles >> General >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Creating Pen and Brush in VC++

Posted By:Abhisek Panda       Posted Date: November 27, 2009    Points: 25    Category: General    URL: http://www.dotnetspark.com  
 

Creating Brush and Pen in VC++ using MFC


Brush and Pen are two components for outputting text and graphics. The selection of a particular brush makes the outline being drawn using that brush. The selection of a pen makes the output of text and graphics by using a particular style. To use a particular brush or pen we have to associate that brush or pen with the device context.

Defining a Brush:-



CBrush:- An object of this component represents a brush with a particular color. The constructor of this component takes the color in RGB format as its argument.

CBrush redBrush(RGB(255,0,0));

Associating Brush with device context:-



To use a brush for outputting, it should be associated with the device context.
Syntax:-
[devicecontext object].SelectObject(&brush object);

This function associates the brush with the device context.

CBrush greenBrush(0,255,0);
CClientDC dc(this);
dc.SelectObject(&greenBrush);

Defining a Pen:-



CPen:- An object of this component represents pen with a particular style, thickness and color. The constructor of this component takes three arguments representing the style, thickness and color.
Syntax:-
CPen [pen object](style, thickness, color);


The style of the pen is represented by a set of predefined constants that begins with "PS_". The commonly used constants are as follows,

PS_SOLID (the style is "_______")
PS_DASH (the style is "-------")
PS_DOT (the style is ".......")
PS_DASH_DOT (the style is "-.-.-.-")

The thickness of the pen is an integer representing width of the pen in pixels.

The color parameter is represented in RGB format

CPen redPen(PS_SOLID,4,RGB(255,0,0));
CPen bluePen(PS_DASH_DOT,3,RGB(0,0,255));

Associating pen to device context:-



To use a particular pen for outputting, it should be associated with the device context.
Syntax:-
[devicecontext object].SelectObject(&pen object);

This function associates the particular pen with the device context.

CPen bluePen(PS_DASH_DOT,3,RGB(0,0,255));
CClientDC dc(this);
dc.SelectObject(&bluePen);
 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

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