473,320 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to calulate width of string for given font

I created RDL file containing TextBox with constant text.
I used the following code to find TextBox <Widthtag value.
However textbox width is too large.

How to find exact width of string for given string ?

Andrus.
float MeasureString(string stringToPaint, string fontName, int fontSize) {

Font font = new Font(fontName, fontSize, FontStyle.Regular);

// Set TextFormatFlags to no padding so strings are drawn together.
TextFormatFlags flags = TextFormatFlags.NoPadding |
TextFormatFlags.NoPrefix;

// Declare a proposed size with dimensions set to the maximum integer
value.
Size proposedSize = new Size(int.MaxValue, int.MaxValue);

Size size = TextRenderer.MeasureText( stringToPaint,
font, proposedSize, flags);
return size.Width;
}

Apr 20 '07 #1
0 1239

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex Shi | last post by:
In php, is there a way obtain the width of a charactor of a certain font? Alex -- ================================================== Cell Phone Batteries at 30-50%+ off retail prices!...
8
by: James Stroud | last post by:
Hello All, I would like for a tkinter text widget to be aware of how big the frame that contains it is, then I would like for it to reset its width to the appropriate number of characters when...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
5
by: John Smith | last post by:
Here is my HTML table formatting code. <table border="1" width="100%"> <tr width = "100%"> <td width="33%">11asdhagdshaskgashjgahjgadhjgdjshdgasjdgajdgadjhgdgahjdgadhjsgad
2
by: Elmo Watson | last post by:
In HTML - for a textbox (input), I would use the 'Size' Attribute In an ASP.Net TextBox - I use 'Width' - - (like 200px) However, for other browsers - Other than IE - the size attribute isn't...
2
by: Benny Raymond | last post by:
Since I have no control over a treeview's scroll bars (i'm drawing icons and text to the right of the treenodes) I've decided to just add some special text to the end of my tree node text which I...
12
by: paii, Ron | last post by:
Sorry about that last one. Does anyone know how to calculate the width a string of text for given Font name and size? I want to buildup a block of text strings to display in a unbound control,...
3
by: kavipriya | last post by:
Hi, Case 1 : Text : "Hi How are 123 ? " Font :Arial Size : 10 Case 2: Text : "Hi How are 123 ? " Font :Times New Roman
30
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.