Click here to Skip to main content
15,891,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working in a winform application where I have to show the text in a fixed area (area of fixed size) although there are more text i.e it should show the possible texts in the accommodated area and leave other text which are not accommodated. Also the text is reach text(the letter size can be small big bold colored etc.).

I tried using the WebBrowser control. But as the area is fixed to display rich text, sometimes the letters are half displayed when the letter size is too large. Am I missing something as far as WebBrowser control is concerned? Or is there any other control which can help ?

Also I am looking for something like the AutoEllipsis property as exists for the Label control.

Any suggestion ?
Posted
Updated 10-Nov-15 20:21pm
v6
Comments
BillWoodruff 11-Nov-15 4:24am    
You could use a RichTextBox as a Label; see:

http://stackoverflow.com/q/15802229/133321

but, that doesn't handle the "show ellipsis" feature you want

do you want to scale the Rich Text content so it fits in a certain fixed size container ?
Digambar Malla 11-Nov-15 4:35am    
BillWoodruff , I want the control should show some portion of message (not exactly everything) in the available fixed space and was thinking to put autoEllipsis for rest of character (something like continued...)

Accurately measuring the size of arbitrary RTF content in a RichTextBox when that content contains multiple Fonts and/or multiple Font Sizes, and/or multiple Font Styles is a hard problem !

1. why don't you just use 'Scrollbars on the RichTextBox: set 'ScrollBars property to 'Both so they'll automatically appear as needed ? Sometimes simplest is best !

2. the only fit-RTF-to-container solution I've seen is by Blake Robertson: [^]; source here: [^]. His GitHub site is discontinued and I have no idea what state his code is in.

3. if you are willing to expand the size of the RichTextBox so the RTF in it is fully visible, there are several solutions I've seen on StackOverFlow. Just search on "RichTextBox fit text."

3.a. another strategy would be to design a UserControl that had both a RichTextBox, and a kind of "activator" (Label ?Button ? Panel ?) that when you clicked it it would either:

3.a.1. expand the size of the RichTextBox to some pre-defined state

or,

3.a.2. activate the ScrollBars

Unless you are a senior developer and very familiar with using API calls in WinForms (P/Invoke), I advise you to just use ScrollBars.

4. well ... wait a minute ... here's a final thought: use a pop-up Form to display the RTF when the user clicks on the "small display window" on the Form.

You can use the technique shown here for showing plain text (one font, one style, on size) in a TextBox: [^] fitted to your TextBox area, then, when the user clicks on it, or clicks some Control: then show a pop-up Form with a RichTextBox.
 
Share this answer
 
v2
Comments
Digambar Malla 12-Nov-15 2:15am    
Really great buddy, awesome response and approach scenario's...As of now, I am going to use Scroll Bar. Many many thanks for your valuable time :)
You should be able to do what you name with the WebBrowser Control. Format your Rich Text as HTML including your font size, color etc and you should be good to go...
 
Share this answer
 
Comments
Digambar Malla 11-Nov-15 4:15am    
Appreciate ur response...please check the exact requirement @Jim

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900