RadRichTextBox Magnification key?

3 posts, 0 answers
  1. Joan VANDERWEYST
    Joan VANDERWEYST avatar
    4 posts
    Member since:
    Mar 2010

    Posted 19 Nov 2014 Link to this post

    I know that you can hold down the CONTROL key and use the mouse wheel to change the magnification in the RadRichTextBox.

    Is there a way to do the same thing without using the mouse wheel?  Can I change the magnification using the keyboard only?

    Also, we do not want to use a separate slider control to change magnification.  Just a simple key combination would be nice.
  2. Todor
    Admin
    Todor avatar
    168 posts

    Posted 21 Nov 2014 Link to this post

    Hello Joan,

    As there isn't an existing command which is responsible for the zoom in/out of a document, you hook up on the RadRichTextBox's KeyUp event and execute the desired logic there. 

    For example, you can use the following code snippet which does what you've described:
    double scalingStep = 0.1;
    this.radRichTextBox.KeyUp += (s,e) =>
        {
            if(!((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control))
            {
                return;
            }
     
            double newWidth = this.radRichTextBox.ScaleFactor.Width;
            double newHeight = this.radRichTextBox.ScaleFactor.Height;
            if (e.Key == Key.Up)
            {
                newHeight += scalingStep;
                newWidth += scalingStep;
            }
            else if (e.Key == Key.Down)
            {
                newHeight -= scalingStep;
                newWidth -= scalingStep;
            }
     
            this.radRichTextBox.ScaleFactor = new Size(Math.Max(0,newWidth), Math.Max(0, newHeight));
        };

    In the example above CTRL + UpArrow Key zooms in, and the CTRL + DownArrow Key combination zooms out.

    I hope this helps.


    Regards,
    Todor
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Joan VANDERWEYST
    Joan VANDERWEYST avatar
    4 posts
    Member since:
    Mar 2010

    Posted 02 Dec 2014 in reply to Todor Link to this post

    Thanks! That worked perfectly!
Back to Top