How can I get the location of a TextBlock's TextTrimming - c#

If I have a long string of text in which the font size and family is adjustable, and it gets texttrimmed a few lines into the TextBlock's window, how do I get the spot or IndexOf or whatever of the point where the string is cut off?
I guess one way to put this is, like an article that spans two pages, I would like to get the indexof the end of the first page so I can know the next word in the article to begin on the second page.

You could search for the cutoff point by iteratively calling GetPositionFromCharIndex.

Related

Free Text Box width limit/wrapping

Hi I use the Free Text Box in my .net application.
I was wondering if there was a way to prevent someone typing one single huge line of text.
Can you set a wrap boundary on it?
I had a short read of the documentation, and I don't think you'll find a native way to do so.
I guess you could use the FreeTextBox.TextChanged event, and check every line in the FreeTextBox.Text property. Mind the fact that it is HTML, and you will probably have to parse it with another third party tool (doing it manually will only give you headaches).
If any of these lines has more characters than an arbitrary length you'll set, create a new line of text with the surplus character, and move the caret to this line.

C# string.Format alignment issue

I have a problem with the alignment of a few names (changed for this question).
with this code I display the names in a richtextbox where it should be in one row with the "Spalte:" after the Names...but it doesn't. Can anybody help me please?
(only the first for-loop is necessary for my question, the next one does another job)
I added a pic what it looks like and how it should be looking. I know I can do it like its in the commented area (doesn't work in every case), but I need to change the code for a few other things so this needs to work....
Here is what I have:
And here is what I want:
Thanks for helping me :D
You have four options:
Change the code for the RichTextBox to use a fixed-width font. Most fonts have variable widths for each character, meaning you can't line things up neatly based on spacing alone.
Use tabs instead of spaces for the layout (and make sure the tab size is large enough to account for variances in your text).
Use a grid control of some type (DataGrid, GridView, etc)
Use a custom control for each row with labels at specific places (and either calculate positions yourself to place them on the form or use something like a FlowLayoutPanel).

WPF character spacing irregular in RichTextBox

I have a problem with character spacing.
Basically I have something like this which comes from a txt file:
****************
*System Details*
****************
Looks nice and uniform, however, when I open have this go into a RichTextBox this happens:
Irregular character spacing example:
I've tried all different properties to try and stretch it, render it etc. but nothing works.
The data is coming in from code-behind OpenDialogBox that stores all the lines of the file in a string[]. A foreach loop then sends the lines into the RTB. (It needs to be a loop as each line gets checked)
Any help it greatly appreciated!
Many thanks
This is most likely a font choice problem. By default WPF uses Segoe UI on Windows 7 and above which is a non-monospaced font. This means that each character will not necessarily take up the same amount of space as each other character leading to issues if you are trying to align characters between lines. The easiest way to get alignment to work is by changing the font to a monospaced font by setting the FontFamily property on the RichTextBox.

How to maintain long text inside RDLC report column ?

I have tried a lot to maintain long text inside RDLC report's columns but it doesn't seem to be adjustable. When some long text appears inside any column then it disturbs the whole report. How to control it, so the text keeps extending downwards in proper and good manner.
Try and put a fixed Column Width and set CanGrow to False and make sure that the Row has it set on True.
If that doesn't work you'll have to edit your datasource before giving it to the reporter. You must break the value into multiple lines based on the length of the string. You can achieve this by inserting System.Environment.NewLine every time it exceeds the size. The exact length at which you need to insert the line breaks depends on your maximum column width and you'll have to calculate this yourself by trial and error until you find the perfect fit.
Edit: Including step by step process for adding break lines based on text size.
Calculate the length of the string and add Environment.NewLine where needed to force the text to break to a new line.
Use Graphics.MeasureString to calculate the size of your text in pixels.
Check if the width exceeds the maximum length of your TextBox.
If the string fits, add it to the final string and continue to step 4.
If the string doesn't fit, continue to step 3.
Remove a character of the string, insert that character to the front of a new (second) sting and repeat step 1. again until the
first string fits.
Check if the second string is empty.
If the second string is empty, we're finished. (The final string can be added to the TextBox / new datasource).
If the second string isn't empty, add an Environment.NewLine at the end of the final string and replace the first string with the
second one and make the second string empty again, repeat the whole
process.
There might be ways of improving this process. For example by breaking the text in fixed predefined intervals and refining it afterwards. Or if there are actual words divided by spaces you could add and remove words instead of characters.
Cut the long-length textbox.
Drag and drop a rectangle there.
Paste the textbox inside the rectangle.
Set rectangle's borders
as the textbox was.
Note: your textbox must be Cangrow:true

how do I get the height of a rich text content after word wrap?

Question A.
Given
A string in rich text format that may have paragraph, tabs, space, line break, indentation, (or even image?)
A width for the word wrapping rich text control/editor
How do I know the height of the content after it have performed all the word wrapping?
Is there something like
int MeasureRichTextHeightAfterWordWrap(string aRichTextContent, int aWidth)?
Otherwise how does those rich text control know how much to autosize?
Do I have to actually place the content on a dummy rich text control, set it's width and get its height with GetPositionFromCharIndex(TextLength-1) afterwards?
Although this does work, it seems to be "wasteful"
Question B.
If I draw plain text onto a plain text memo/control/editor,
and manually draw string with manually calculated indentations, breaks, word wrappings to pretend the RTF.
Is it easier or harder?
Edited to make it look clearer
and sorry if my English looks like a student cause it's not my native language.
Sorry about my bad first attempt at an answer. I DID find an answer for measuring inside a RichTextBox. Apparently you have to use Win32 GDI API calls.
http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.windowsforms.controls/2004-09/0574.html
I found this by changing my search after running across this nugget, which explains why there's not a pure .NET way to do it:
http://www.developmentnow.com/g/38_2005_10_0_0_626243/I-dont-believe-this-code-gives-the-correct-RichTextBox-string-size.htm

Categories

Resources