Linked Questions
14 questions linked to/from TextRenderer.MeasureText and Graphics.MeasureString mismatch in size
48 votes
12 answers
60k views
Determine Label Size based upon amount of text and font size in Winforms/C#
I'd like to know if there's a better approach to this problem. I want to resize a label (vertically) to accomodate certain amount of text. My label has a fixed width (about 60 chars wide before it ...
61 votes
6 answers
77k views
Calculate the display width of a string in C#?
A Java version of this question was just answered, and, well, I don't know how to do this in .net. So how do you calculate the display width of a string in C# / .net?
9 votes
2 answers
8k views
Compute font size to fit text into a specific width
I have a changing sized image, and I would like to know which font size I should use to fit that dynamically changing size. As you know, there is a Graphics.MeasureString method, which calculates the ...
4 votes
1 answer
3k views
TextRenderer with Graphics transform
I've been working on a custom control and I've run into an issue with TextRenderer acting a bit surprisingly. In my OnPaint event I apply transform to the Graphics object to compensate for the scroll ...
2 votes
3 answers
4k views
How to use MeasureString in C# to set table column width?
I have a pretty quick (and I'm hoping basic) question. I'm modifying some C# code for my company's website. The code draws a table for me in fixed columns, the data for which is pulled from a database....
2 votes
1 answer
4k views
Windows Forms label resizing issue
I have a winform application on which I place a label. I change the text of the label dynamically from a background thread. The text change fires an event that is supposed to resize the label. ...
0 votes
1 answer
3k views
Automatically resize font size of DataGridView cell text?
I have a DataGridView that I use as sort of a graphic for a 2D array. My issue is that I cannot figure out how, or if it is possible, to automatically scale the text in the cells to the size of the ...
0 votes
1 answer
825 views
Compress text to fit within a control's displayed width
In my C# WinForms application, I have a control in which I display some text to the user on screen. For time being, assume it is a TextBox. My requirement is if the text does not fully fit within the ...
3 votes
1 answer
800 views
Unable to get correct Size of DrawnText using TextRenderer
Im drawing Text using the following code onto a Bitmap GraphicsPath pth = new GraphicsPath(); var style = (int)myfont.Style; pth.AddString(tcaption.Text, myfont.FontFamily, style, myfont.Size, point, ...
1 vote
1 answer
894 views
How to correctly measure characters in string using TextRenderer?
I am trying to draw a multi-colored string. As there are no default methods to do this, I am trying to draw the string char by char myself using TextRenderer.DrawText, however, it does not report ...
-3 votes
1 answer
814 views
How to use TextMetrics to measure the dimensions of a string
I'm trying to get the height of a string. I've come across MeasureString but it's inaccurate for what I need it for - too small for what MS Word is showing (okay, this is probably another topic so if ...
2 votes
1 answer
376 views
Adapt the height of a TextBox
I am working on a UserControl that contains a multiline TextBox. When using my control, one will be able to set the text that will be displayed. The TextBox should then adapt its Height to make the ...
2 votes
1 answer
171 views
Get Preferred Width to Display String in With Given Font on Web Form [duplicate]
TL;DR It seems the only piece I'm missing now is how to find the preferred width of a cell as it's being created. I need a replacement for Graphics.MeasureString that works for web forms. ORIGINAL ...
0 votes
1 answer
94 views
How to set CheckedBoxList to MaxWidth of Item Conents
I have tried a lot of things. Rectangle r = checkedListBox1.GetItemRectangle(0); checkedListBox1.ClientSize = new Size(checkedListBox1.PreferredSize.Width, checkedListBox1.PreferredSize.Height); Here ...