How to detect line overflow from string in C #?

I wanted to know how to wrap words in C # when I came across a very good solution to my problem of text-translating text to a string in this URL . Unfortunately, I do not have enough reputations to directly ask the OP about one specific problem . I have (and most likely people dealing with this will have an indefinite period)

Description of the problem:
I can wrap a string if it should be wrapped with words using this code:

Graphics PAddress = e.Graphics; SizeF PAddressLength = PAddress.MeasureString("Residential Address: " + RAddressTextBox.Text, new Font(fontface, fontsize, FontStyle.Regular),700); PAddress.DrawString("Residential Address: "+PAddressLength + RAddressTextBox.Text, new Font(fontface, fontsize, FontStyle.Regular), Brushes.Black, new RectangleF(new Point(pagemarginX, newline()),PAddressLength),StringFormat.GenericTypographic); 

However, I could not find a place to get the trigger whenever the word length overflowed from one line.

, eg:
In LINE-2 of this code, when the word length exceeds 700px , it goes to the next line. He does this by following RectangleF in wordwrap. It does this automatically , which is a problem, as it makes it difficult to determine if it crossed 700 pixels or not.

This is the format in which information is displayed whenever I tried to print PAddressLength :

{Width = 633.1881, Height = 47.14897}

I think that if I can extract the width value from this using PAddressLength.Width, then I can partially solve this problem. But with this, I will need to calculate whether the remaining space (i.e. 700px - 633.1881px) will place the next word or not (if there is one)

SOLUTION OF A PROBLEM:

  • I already know how word-wrap is when the string is longer than indicated using Graphics.MeasureString as indicated in this solution in another question.
  • But this process happens automatically, so I want to know how to determine if word wrap has occurred (and how lines can be wrapped with each line 700 pixels wide)
  • I need to find out the number of lines that were wrapped in order to find out the number of times to execute the newline () function that I wrote, which gives the corresponding line spacing when each time is executed.

OPTIONAL, (bonus question, may or may not resolve) Is there a way to extract the value 633.1881 , and then calculate whether the next word in (700 - 633.1881) px fits or not?

+5
source share
1 answer

MeasureString has an overload that returns the number of lines used in the out parameter: https://msdn.microsoft.com/en-us/library/957webty%28v=vs.110%29.aspx

+2
source

Source: https://habr.com/ru/post/1245819/


All Articles