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

Set the caret position to specific offset.

7 Answers 721 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rotem
Top achievements
Rank 1
Rotem asked on 16 Nov 2011, 10:43 AM

Hi,

I’m using RadRichText and I’m trying to move the caret to specific offset from the start of the document (or specific row and column).

I saw on the forum that in order to move the caret I need to use
richTextBox.Document.CaretPosition.MoveToPosition

That gets DocumentPosition as parameter. But I can’t create documentPosition from desired text position.

How can I set the caret position from the beginning of the document?

By the way,

The Document position API help page doesn’t work.

(http://www.telerik.com/help/silverlight/telerik.windows.documents-telerik.windows.documents.documentposition_members.html)

Thanks,

Rotem.

7 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 22 Nov 2011, 09:08 AM
Hello Rotem,
You can navigate the position to specific line/character using the following methods:
private void Button_Click(object sender, RoutedEventArgs e)
{
    this.radRichTextBox.Document.CaretPosition.MoveToFirstPositionInDocument();
 
    // this will move the position down (to the next line)
    this.radRichTextBox.Document.CaretPosition.MoveDown();
 
    // alternatively, you can use this combination to move to the next line start
    //this.radRichTextBox.Document.CaretPosition.MoveToCurrentLineEnd();
    //this.radRichTextBox.Document.CaretPosition.MoveToNext();
 
    // this will move to the next position
    this.radRichTextBox.Document.CaretPosition.MoveToNext();
 
    // return the focus to the RadRichTextBox
    this.radRichTextBox.Focus();
}
You can read more about positioning in this article.
The DocumentPosition.MoveToPosition is useful if you want to move the caret to an instance of DocumentPosition, obtained for example from selection or search.
The actual link to the Document position members API is this one. Could you please share the page you've found invalid link on, so we can update it with the correct link?

All the best,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Vikash
Top achievements
Rank 1
answered on 27 Apr 2012, 11:32 AM
How to set tabindex in richtextbox.I am setting like given sample code.It not working properly.richtextbox tab comes after button tab.
<telerik:RadMaskedTextBox TabIndex="4" Mask="" MaskedText="" MaskType="None" Name="txtTerms" FontFamily="Verdana" Margin="132.991,151.144,12,0" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment" ValueChanged="txtTerms_ValueChanged" />
  
       <telerik:RadRichTextBox  TabIndex="5"  Name="rtbDescription" DocumentInheritsDefaultStyleSettings="True" AcceptsTab="True" IsSpellCheckingEnabled="False" IsEnabled="True" FontFamily="Verdana" Margin="132.991,186.287,10,0"  Height="145" VerticalAlignment="Top">
       </telerik:RadRichTextBox>
  
       <telerik:RadButton TabIndex="6" Content="Save" Style="{DynamicResource greenbutton}" Name="btnSave" C ursor="Hand"  HorizontalAlignment="Right"  Margin="0,392,201,0" FontFamily="Verdana" Width="49"  Foreground="White" BorderBrush="{x:Null}" BorderThickness="0" Height="22" VerticalAlignment="Top" Click="btnSave_Click"/>
0
Andrew
Telerik team
answered on 02 May 2012, 09:11 AM
Hi Vikash,

Indeed this is a bug in RadRichTextBox and we will try to fix it as soon as possible. We updated your Telerik points in appreciation for your involvement.

All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Vikash
Top achievements
Rank 1
answered on 24 May 2012, 09:50 AM
Hi Telerik Team,

How to apply theme in RadRichTextBox.I am using this code:But it not working
<telerik:RadRichTextBox  IsTabStop="False"  TabIndex="2"  Name="rtbDescription"  telerik:StyleManager.Theme="Expression_Dark" DocumentInheritsDefaultStyleSettings="True" AcceptsTab="True" IsSpellCheckingEnabled="False" IsEnabled="True" FontFamily="Verdana" Height="145" VerticalAlignment="Top" Margin="12,203,131,0">
</telerik:RadRichTextBox>
0
Andrew
Telerik team
answered on 28 May 2012, 06:37 PM
Hello Vikash,

You need to add a reference to the appropriate theme assembly. In your case that would be Telerik.Windows.Themes.Expression_Dark.dll. Furthermore, in order to have the theme apply to all pop-ups that the editor uses, the theme should be set on application level before the UI is created (i.e. before InitializeComponent()):

StyleManager.ApplicationTheme = new Expression_DarkTheme();

You can see how the editor looks like when this theme is applied in the Theming example of the ClickOnce demos.

Kind regards,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Vikash
Top achievements
Rank 1
answered on 14 Jun 2012, 11:54 AM
Hi Team,
Can you please sent me a sample project to apply theme in RadRichTextBox. I am applying
StyleManager.ApplicationTheme = new Expression_DarkTheme(); in App.xaml.cs  at Application_Startup event.Theme works fine on all other control except RadRichTextBox. Please reply ASAP.
0
Andrew
Telerik team
answered on 19 Jun 2012, 08:39 AM
Hi Vikash,

We created a sample project where the Expression Dark theme is applied to RadRichTextBox and we are attaching it to this post. Please notice that the control is in Paged layout mode. If you change the mode to Flow for example, the scrollbars would be using the theme colors but the RadRichTextBox will remain white with black letters.  

All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Rotem
Top achievements
Rank 1
Answers by
Boby
Telerik team
Vikash
Top achievements
Rank 1
Andrew
Telerik team
Share this question
or