Questions tagged [measurestring]

14 questions
6
votes
2 answers

"A generic error occurred in GDI+" while using MeasureString

I have an overriden (WinForms) MemoEdit control (unfortunately I can't give you the code). If I enter more than 32000 characters, it raises an error "A generic error occurred in GDI+" I thought that there's an error (exception) in my control but…
5
votes
3 answers

How do I implement word wrap?

XNA has Spritefont class, which has a MeasureString method, which can return the Width and Height of a string. I'm trying to understand how to create a method that will efficiently return a string with Environment.Newline inserted in the right…
user1306322
  • 8,561
  • 18
  • 61
  • 122
4
votes
2 answers

Does/can the Graphics MeasureString method take the width of the container and line wrapping into account?

I have a need to calculate the height of a string given that I already know the width. For example if have a string like "Curabitur semper ipsum semper nulla dictum, vel vulputate elit fringilla. Donec nec placerat purus, ut blandit lectus.…
Andy Evans
  • 6,997
  • 18
  • 72
  • 118
3
votes
1 answer

Get height of row where the cells have WrapText set

I am trying to compute the height of the row I'm inserting into my excel sheet. The row's cells are formatted with WrapText=true, so the height of the row is not fixed. Accessing row.Height will return null. I was thinking of using something similar…
Karim
  • 247
  • 4
  • 11
3
votes
1 answer

GDI+ MeasureString() is incorrectly trimming text

I am trying to complete a code that can layout text on the screen. The following C# code placed in the Paint event handler of an otherwise empty Windows Form is an example: string[] s = new string[] { "Sample text ", "to test", " this layout ",…
user1476997
  • 31
  • 1
  • 2
2
votes
1 answer

How to compute the correct width of a digit in pixels?

I have a custom control that may have user customizable Font in future (the zoom is already implemented). I must fill a rectangle under two digits that form a base-10 number. I have different colors for zero, one or both of the digits. With the font…
silviubogan
  • 3,343
  • 3
  • 31
  • 57
2
votes
2 answers

C# Does a label ignore whitespaces when querying MeasureString?

I have been trying to find an error in a ticker tape type application. Hopefully this background is not to long. Background: The ticker tape needs to display characters starting from the right and then scroll to the left. I need to use a label (or…
user3725237
  • 131
  • 2
  • 10
2
votes
2 answers

How to estimate the length of a to-be-printed string?

I am trying to estimate the length of a printed string. Font newFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point); label1.Font = newFont; labe1.Text = "300028"; Graphics g = Graphics.FromHwnd(label1.Handle); SizeF txtSize =…
Klaus78
  • 11,648
  • 5
  • 32
  • 28
2
votes
2 answers

Fit the text inside a TextBox in VB.net windows forms

In one of my application i require to place the text inside a textbox and textbox width and height must change according to the length of text. So i am using TextSize = gr.MeasureString(textcontent, TextFont) where textcontent is content of text…
IT researcher
  • 3,274
  • 17
  • 79
  • 143
1
vote
1 answer

System.Drawing.Graphics trim end of string?

While working on a text render algorithm, I stumbled across a strange behavior of the Graphics.MeasureString() method. It seems like it internally trims the end of a string. g.MeasureString("d", font).Width //is 13.289278 g.MeasureString("d ",…
Florian Gl
  • 5,984
  • 2
  • 17
  • 30
0
votes
1 answer

Custom Measure String in C# without Graphics.MeasureString

I am trying to create an Image with a Caption/Text on it for Youtube-Thumbnails. Following Rules are defined: The Text is the Title of the Video and always changes from Thumbnail to Thumbnail. The Porgram uses a pre-defined Text-Width which must…
Snickbrack
  • 1,253
  • 4
  • 21
  • 56
0
votes
2 answers

Why Graphics.MeasureString measures Arabic strring incorrectly?

I have an Arabic string, which is result of concatenation of Arabic string and " : 100". This string is measured and drawn incorrectly. Why? public partial class Form1 : Form { string strIncorrectMeasure = "مەھسۇلات باھاسى" + " : " +…
Eugene Maksimov
  • 1,504
  • 17
  • 36
0
votes
1 answer

Generic function to return String measure (Graphics.MeasureString)

In C# or VB.NET how I could write a generic function which only should need to pass a string and a font to return the measure of the font? This is What I've tried: Private Function Get_Text_Measure(ByVal text As String, _ …
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
0
votes
3 answers

MeasureString() doesn't return enough width

I have the following code to create a Label on a PictureBox: Label l = new Label(); l.Text = _name; l.Size = CreateGraphics().MeasureString(_name, l.Font).ToSize(); l.BackColor = Color.White; but the label is always dropping the last character. If…
Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195