how to set document view to begining of the text

8 posts, 0 answers
  1. deri
    deri avatar
    11 posts
    Member since:
    Sep 2016

    Posted 22 Dec 2016 Link to this post

    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.

  2. deri
    deri avatar
    11 posts
    Member since:
    Sep 2016

    Posted 22 Dec 2016 Link to this post

    hello again,

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

    Thanks

  3. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    171 posts

    Posted 22 Dec 2016 Link to this post

    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.
  4. deri
    deri avatar
    11 posts
    Member since:
    Sep 2016

    Posted 23 Dec 2016 Link to this post

    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.

  5. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    171 posts

    Posted 23 Dec 2016 Link to this post

    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.
  6. deri
    deri avatar
    11 posts
    Member since:
    Sep 2016

    Posted 28 Dec 2016 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    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.

  7. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    171 posts

    Posted 28 Dec 2016 Link to this post

    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.
  8. deri
    deri avatar
    11 posts
    Member since:
    Sep 2016

    Posted 29 Dec 2016 in reply to Lance | Tech Support Engineer, Sr. Link to this post

    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.

Back to Top