Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 image.so i need to align that in a rectangle.do anyone know the simple way to do this?
my code:
C#
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
Updated 20-Aug-12 8:15am
v2
Comments
[no name] 20-Aug-12 14:17pm    
FontStyle.Bold should give you a hint.

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.
 
Share this answer
 
Comments
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...
--SA
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900