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.
Related
I'm trying to do some automatic tests if the strings of a translated Application still fits the existing UI. The translation process just takes an existing resource assembly translates the contained resources and creates a new resources assembly for the new language. Easy but that way there is no garantee that the translations still fits into the UI (the UI is not involved in the translation process) and might get truncated all over the place. So for an automatic check i would need an idea on how to find truncated Text on the UI.
I tried so far:
Measuring the client size of a control, measuring the text length and
compare them. Doesn't work since there seem to be no way to find out
the ~real~ client size of a control that is used for putting text on
it (For a Button its not just Size minus Padding for example)
Setting AutoSize to true and checking if the control grows. That
would only work for non-wordwrapping controls and there seem to be
no sharp limit here. A control might grow to fit the Text on its
surface when setting autosize but the Text was fitting before
also. The margins might have been pretty narrow but the Text where
fitting.
Are there more idea that might work? Or are there some tweeks that might make the above mentioned ways work? Would be great if there where a simple Win API method i could call that would just give me the actual shown text of a control not the text a programmer/programm whishes to be shown on a control.
Get the amount of the characters from the non translated version and differentiate them against the length of the translated version then multiply the current controls width by the difference. It could look something like this.
float scalingAmount = 0.1 //This is just an example value, you'd probably want to adjust this yourself
float difference = oldLabel.Text.Length - label.Text.Length;
label.Width = oldLabel.Width * (difference/scalingAmmount)
Either C++ or C# solutions are welcome.
I have the index of a character in a text displayed in a RichEditCtrl. I need to know its format (is it bold, red, etc) without selecting it.
Thank you all.
Using the base CRichEditCtrl, there is no way to get the format of a char without selecting it. If you don't want to change the selection, then save the start/end position of the current selection, select the character you want the format of, call CRichEditCtrl::GetSelectionCharFormat(), and then restore the original selection of the rich edit control.
I have an application where we replace place holding text with other text at run time.
While doing so I have to add character ellipses if the string goes beyond some predefined width.
So I do not have a DrawingContext available nor i have a Graphics.Measure available.
I used FormattedText but I was unable to extract the ellipted text.
I could never find the right way to use a formatted text like this.
Please help.
For WinForms, you can use the TextRenderer.MeasureText function,
and thanks to the comment from vcjones, using the method described at http://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/ for WPF.
i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.
Ex: i Typed Ram then it gives *Ram*esh .
The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.
That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.
I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.
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