Click here to Skip to main content
13,054,018 members (65,668 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i want to draw a sting like my name is Tom and people love me in an image.but i don't know how, can anyone help me. i want to copy a formatted long text in a richtext box and after that write it on an i need to align that in a anyone know the simple way to do this?
my code:
imgInput = bmpinput;
            grfInput = Graphics.FromImage(imgInput);
     SolidBrush drawBrush = new SolidBrush(Color.Black);
            StringFormat drawFormat = new StringFormat();
            drawFormat.FormatFlags = StringFormatFlags.FitBlackBox;
            drawFormat.Alignment = StringAlignment.Center;
  grfInput.DrawString(ord.q1,new Font("Arial",x,FontStyle.Regular,GraphicsUnit.Pixel), drawBrush, new RectangleF(0, 0,877/3, 620/8 ), drawFormat);
Posted 20-Aug-12 8:11am
Updated 20-Aug-12 8:15am
Wes Aday104.2K
Wes Aday 20-Aug-12 14:17pm
FontStyle.Bold should give you a hint.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The graphics classes won't take rich text. You need to position the bold words yourself and make them bold. You can use Graphics.MeasureString to work out where one word ends to put the next one in bold.
Sergey Alexandrovich Kryukov 20-Aug-12 14:32pm
The idea is quite correct, but unfortunately OP will have problems using this method.
The problem is: Graphics.MeasureString is so inaccurate that there is a little hope to get smooth text. If you look around, you will see many UI GDI-based .NET applications where some texts are not fit in their clip regions (and hence clipped off) or overlap with other texts. This is because this method does not take into account things like hinting.

I used to use some more accurate code using some solutions I found of forums, but unfortunately, none of them (I mean only those using GDI) were not 100% accurate in my tests.

So, this is a problem which probably remains open, too bad...
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

F.moghaddampoor 23-Aug-12 6:46am
Dear you didn't read the question care fully, i have a long text with some words bold and some words in regular shape,and i want to write them in a rectangle alligned so it sobvious i cant find the position of end of a word and start to write the other portion bold and then switch to regular.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100