how to set document view to begining of the text

10 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
    465 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
    465 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
    465 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.

  9. deepak
    deepak avatar
    1 posts
    Member since:
    Jul 2017

    Posted 25 Jul Link to this post

    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.

  10. Boby
    Admin
    Boby avatar
    638 posts

    Posted 26 Jul Link to this post

    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.
Back to Top