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

Change Section Style Programmatically

4 Answers 78 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Stergios
Top achievements
Rank 1
Stergios asked on 10 Nov 2012, 05:16 PM
Hi,
I use the RichTextBox control to display a document composed by a number of Sections (Telerik.Windows.Documents.Model.Section). I want to programmatically change the border color when a user moves the cursor over a section or presses the left mouse button on a section.

How can I implement this functionality to determine the selected Section and then change its styling properties?

Thanks

4 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 14 Nov 2012, 02:10 PM
Hi Stergios,

You can use the active editor presenter to determine the document position from a point obtained in a mouse event the following way:

DocumentPosition position = this.radRichTextBox.ActiveEditorPresenter.GetDocumentPositionFromViewPoint(e.GetPosition(this.radRichTextBox));
Section section = position.GetCurrentSectionBox().AssociatedSection;

Such event can be the MouseMove of the RadRichTextBox. For performance reasons you can limit getting the position to several times in a second.

Having the section you need, you can apply any style.

Don't hesitate to contact us if you have other questions.

All the best,
Martin
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Iva Toteva
Telerik team
answered on 14 Nov 2012, 02:23 PM
Hi Stergios,

Having answered your question about getting the current section, we are still a bit confused over what modifications you wish to perform on it. Sections do not have a border color and the relationship between pages and sections is not 1 to 1.

Could you share some details on your goal? What exactly do you wish to change in the document and should it be for presentation purposes only, or should be persisted when you save the document?

Looking forward to your reply.

Kind regards,
Iva Toteva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Stergios
Top achievements
Rank 1
answered on 15 Nov 2012, 06:22 AM
Hello Iva,

I want to implement the following scenario:
- My content is composed by individual blocks of information defined in xml files.
- Each block has a descriptive content (text, tables etc) and an associated image.
- All the blocks should be displayed on the same page as a scrollable flow, while the user will be able to select a single block. 
- Upon selection, the block should be highlighted (e.g. by setting a border around it or by changing its background color) and the corresponding image will be displayed. 

I've successfully implemented a prototype using the standard silverlight RichTextBox control using a ListBox as the flow container and RichTextBox controls as ListBox items, represanting each block of information.

Now I want to extend this prototype using the RadRichTextBox instead of the standard RichTextBox control in order to use its built-in capabilities for searching, zooming and pdf exporting. Of course I could use a StackPanel or a ListBox and create a list of RadRichTextBox controls, but then I have to orchestrate the functionalities because searching, zooming and exporting have to apply to all the RadRichTextBoxes at once. Also, by using multiple RichTextBox controls I've notice that the performance is slow (when setting the RadRichTextBox Document property).

So, I decided to create a single RadRichTextBox (flowing mode) to hold the different blocks of information as Sections. Using this approach, zooming, searching and exporting is siplified but I have to solve the problem of Section selection.  

Best Regards,
Stergios
0
Accepted
Boby
Telerik team
answered on 19 Nov 2012, 10:05 AM
Hello Stergios,
Similar behavior can be achieved using custom layers. Please find attached a demo which "selects" the clicked Section using the SelectedSectionsLayer class and the Section.Tag property. Similar demo, highlighting current word/line, can be found it the online examples.
Note that the attached demo will work correctly only in Flow layout mode, where each section has exactly one section layout box.

Don't hesitate to contact us if you have further questions.



Greetings,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Stergios
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Iva Toteva
Telerik team
Stergios
Top achievements
Rank 1
Boby
Telerik team
Share this question
or