C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » General »

Creating Pen and Brush in VC++


Posted Date: 06 Nov 2009    Resource Type: Articles    Category: General
Author: Abhisek PandaMember Level: Gold    
Rating: 1 out of 5Points: 10



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




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Creating Pen and Brush  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Numeric and Date Functions in VB.NET
Previous Resource: Outputting text and graphics in VC++
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use