This is a migrated thread and some comments may be shown as answers.

Calculating the maximum number of visible characters in a single RichTextBox line

1 Answer 595 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 12 Sep 2014, 06:10 PM
I am trying to create a fixed 'character ' based ruler using the RichTextBox control.   The RTB control
will only contain one line of text that will not wrap, thus I am looking for a way to programmatically calculated the maximum number of visible characters in a RTB control based on the RTB width and the style (monospaced).

MSDN example:  http://msdn.microsoft.com/en-us/library/9bt8ty58(v=vs.110).aspx

Also is there a way to turn off the RTB scrollbars?

Thanks

erik

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Sep 2014, 12:27 PM
Hello Erik,

Thank you for writing.

I am not sure if the RadRichTextBox is the appropriate control for your specific case. You can use the RadTextBox instead. Thus, you will be able to display a single row plain text and no scroll bars will be displayed. I would like to note that the Graphics.MeasureString method is suitable to calculate the exact SizeF required for a specific string. However, when you have a specific width, you can not determine a definite maximum number of characters that can fit in the given width because of the specificity of each character. For example in width X you can fit 10 characters 'w' or 20 characters of 'i' just because 'w' is much wider than 'i'. You can just use the SizeF result returned by the Graphics.MeasureString method in order to determine whether the currently available string needs bigger width than the control's width.

As to the scroll bars question, you can turn off the vertical RadRichTextBox's scroll bar by manipulating the RadRichTextBox.DocumentView.Scroller.VScrollState property.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Erik
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or