Link to home
Start Free TrialLog in
Avatar of alexatsearidge
alexatsearidgeFlag for Canada

asked on

Using GDI+ to draw strings

Hi all,

  I need to use the DrawString method in GDI+ but when I am unable to create a Font object.  I've created an activeX control that creates a Font object just fine but when I try to use it in a dialog application it will not let me.  The method of implimentation I've been using is:

Font font(fontFamily, etc, etc);

  I'm sure there is some initialization I need to perform but I have no idea.  If someone could somewhat detailed information on how to create the font and any other useful tips for using DrawString I would appreciate it.
Avatar of jkr
jkr
Flag of Germany image

How are you initializeing the Font? E.g.

FontFamily fontFamily(L"Arial");
Font font(&fontFamily, 16, FontStyleRegular, UnitPixel);

should work fine. See e.g. http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingtextandfonts.asp ("Using Text and Fonts"), you'll also find sample code there. Regarding the title of your Q, see http://msdn.microsoft.com/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingtextandfonts/drawingtext.asp ("Drawing Text "):

FontFamily  fontFamily(L"Times New Roman");
Font        font(&fontFamily, 24, FontStyleRegular, UnitPixel);
PointF      pointF(30.0f, 10.0f);
SolidBrush  solidBrush(Color(255, 0, 0, 255));

graphics.DrawString(L"Hello", -1, &font, pointF, &solidBrush);
Avatar of alexatsearidge

ASKER

That is the exact format I am using but one compile error I get is "Font is an ambiguous symbol".  I'm not at my developement machine at the moment but once I get a chance I'll check the exact errors.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial