|
|
|
When you're dynamically drawing text (either on a Windows Form or Web Form application), you may need to calculate the width and height of a string printed with a particular font. This is easy with the Graphics class's Measure string method, that takes in input the string being measured, and the font it will be printed with. Follows an example: |
Click here to copy the following block | Dim bmp As New Bitmap(400, 200, Drawing.Imaging.PixelFormat.Format16bppRgb565)
Dim gr As Graphics = Graphics.FromImage(bmp)
Dim stringSize As SizeF = gr.MeasureString("Test string", _ New Font("Courier New", 18, FontStyle.Bold, GraphicsUnit.Pixel)) |
Finally you can read the Height and Width properties of the returned SizeF variable (stringSize) in the example above.
|
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
 |

|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|