Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# string font
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:
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 9:11am
Edited 20-Aug-12 9:15am
Wes Aday94.3K
v2
Comments
Wes Aday at 20-Aug-12 14:17pm
   
FontStyle.Bold should give you a hint.
Rate this: bad
good
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.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
F.moghaddampoor at 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)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Aug 2012
Copyright © CodeProject, 1999-2014
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