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

how to set document view to begining of the text

9 Answers 256 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
deri
Top achievements
Rank 1
deri asked on 22 Dec 2016, 08:16 AM

Hello Telerik Team,

currently i'm building a text editor with 4 column layout (grid - raddocking split into 2 RadPaneGroup - grid). the first grid is used to list all of the document/file that can or being edited and its document is showed in the first radpane. the second grid is used to list all of the document or file that exist

in the user folder documents (docx, pdf, jpg etc), and if the user click one of its file, the file is opened in the second radpane. So thats the short stories.

 

now my concern is to the RichTextBox control (that show inside the radpane) used to view or edit the docx file, when i open the file,it is always showed in the most left side of the page (so is the vertical scrollbar), somehow its not so nice to look in the first impression, i had try to custom the decrease the scale factor but it still not so nice in the user eyes. So i want the document showed in the beginning of the text (like when we open document in MS Word, its always viewed in the beginning or the first text right ?), is it possible, please help me.

 

thanks in advance.

9 Answers, 1 is accepted

Sort by
0
deri
Top achievements
Rank 1
answered on 22 Dec 2016, 09:41 AM

hello again,

here i post an example of the running program pictures. hope its more easy to understand than my english.

Thanks

0
Lance | Manager Technical Support
Telerik team
answered on 22 Dec 2016, 07:59 PM
Hello Deri,

The RadRichTextBox has a Positioning API that lets you move the caret to anywhere you want in the document.

Since you want the caret to be at the top of the document, you can use the following code to move the very beginning:

radRichTextBox.Document.CaretPosition.MoveToFirstPositionInDocument();


Note: If you also want to put the focus in the RadRichTextBox, you can do the following after moving the CaretPosition:

radRichTextBox.Focus();


If you have any further questions, or if this approach doesn't work for your needs, please let us know.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
deri
Top achievements
Rank 1
answered on 23 Dec 2016, 11:07 AM

Hello Lance,

thanks for your fast response, unfortunately it's not working (or maybe it did but didn't meet my requirement). You see my app is divided into 4 column, the center two is too small for displaying a document (at least for my laptop, different story if a wide screen is used), and when the document is loaded for the first time, its only showing the half page to the left because its page position is at the most left. for now i decrease the scale factor so i can see the whole text document.

any better idea? thanks.

0
Lance | Manager Technical Support
Telerik team
answered on 23 Dec 2016, 09:49 PM
Hello Deri,

My apologies, I see the document on the left part of your screenshot is what you were looking for.

Yes, you are correct. Setting the zoom level through the ScaleFactor property is your best option to see all of the content. For example, and 80% zoom would be:

radRichTextBox.ScaleFactor = new Size(0.8, 0.8);


Scrolling

Alternatively if, you just want to scroll the document, you can use the offset like this:

// This also works for vertical offset
 
// Get
double offset = this.radRichTextBox.HorizontalOffset;
 
// or set
this.radRichTextBox.ScrollToHorizontalOffset(offset);

Please let us know if you have any further questions.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
deri
Top achievements
Rank 1
answered on 28 Dec 2016, 06:41 AM

hello Lance,

thanks for your support, and sorry for late response. Yes i want the horizontal scrollbar to be automatically positioned where the most left text take place (not the most left page) when the document load. i had try that solution before, but the scrollbar is still in the initial position (offset 0), even it doesn't take effect when i give a value to the offset.

0
Lance | Manager Technical Support
Telerik team
answered on 28 Dec 2016, 05:28 PM
Hi Deri,

You might be using the wrong values for the offset and hitting the edge of the scrollable area. I've attached a small demo app to show you how to use the offset to get to the middle of the document.

There are some things that are helpful to know in order to understand the size of the document compared to the size of the visible area. There is a document width, a ScrollableWidth and a ViewportWidth. The viewport width is what you want to use to determine the center of the area to scroll to.

Heres the the code to accomplish scrolling to center of the document:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    Debug.WriteLine($"Before scroll - Horizontal Offset: {radRichTextBox.HorizontalOffset}");
             
    var middle = radRichTextBox.ViewportWidth / 2;
             
    radRichTextBox.ScrollToHorizontalOffset(middle);
             
    Debug.WriteLine($"After scroll - Horizontal Offset: {radRichTextBox.HorizontalOffset}");
 
    // Here are some other properties that might be useful for you if
    // you want to know how big the document is compared the visible area
    //radRichTextBox.ScrollableWidth
    //radRichTextBox.Document.DesiredSize.Width
}


Give my demo app a try. Load in any docx file, then click the "Scroll To Center" button to see it in action.

Let us know if you have any further questions.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
deri
Top achievements
Rank 1
answered on 29 Dec 2016, 06:28 AM

Thanks Lance, you're the man.

the ScrollableWidth prop works for me, while Document width throw an exception, and ViewportWidth didn't make any effect as the value still 0.

thank you Telerik Team.

0
deepak
Top achievements
Rank 1
answered on 25 Jul 2017, 07:07 AM

Hello Telerik Team,

I have some record, in a record i have one RadRichTextBox, in that text box i have some content with list(numeric and bulletsd),I don't set any alignment property by default its left align, i saved record and then i navigate to other record.When i come back to that previous record that time these list contents are shifting to right side.

Please provide solution.

0
Boby
Telerik team
answered on 26 Jul 2017, 06:12 AM
Hello Deepak,

The issue seem unrelated to the orignal content of the post. Could you please start separate thread and provide some more information. What would be most helpful would be to export the document to XAML using the XamlFormatProvider and send it to us for further investigation. Also could you confirm that you are exporting the document to HTML, and then importing the HTML again?

I guess that the issue is one of the following:
RichTextBox: The default indentation of the list bullets has different visualization when exported to HTML format
RichTextBox: The indentations of a paragraph in a list are changed on export/import to HTML

but we will need more info to confirm.

Regards,
Boby
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
deri
Top achievements
Rank 1
Answers by
deri
Top achievements
Rank 1
Lance | Manager Technical Support
Telerik team
deepak
Top achievements
Rank 1
Boby
Telerik team
Share this question
or