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

Scroll up/down with keyboard shortcuts with PdfViewer

4 Answers 360 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
LT
Top achievements
Rank 1
LT asked on 28 May 2019, 11:45 PM

Hi,

I am overriding ProcessCmdKey to detect when a user press a combination of keys to scroll up and down in the pdfViewer. I'm currently using .PageUp() and .PageDown(), but of course that goes up and down whole pages.

I understand that pdfViewer already has shortcuts using the arrow keys, but that requires that the pdfViewer control be in focus. For our purposes, the user prefers to not lose focus on whatever control they are using, for example, typing in data from the pdf without losing focus of the textbox.

Is there any way that I can use the native function of the Up and Down keys with pdfViewer without requiring that the pdfViewer control be in focus? If I cannot do so, how may I replicate scrolling behavior with my own chosen shortcuts?

        private void ScrollPDFViewer(Keys keyData)
        {

            if (keyData == (Keys.Up | Keys.Control))
            {
                this.radPdfViewer.PageUp();

 

// this.radPdfViewer.PdfViewerElement.Scroller.UpdateScrollValue();
            }
            else if (keyData == (Keys.Down | Keys.Control))
            {
                this.radPdfViewer.PageDown();
            }
        }

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 29 May 2019, 11:37 AM
Hi LT,

You can use the form events for this. You need to set the KeyPreview property as well: 
public RadForm1()
{
    InitializeComponent();
    this.KeyPreview = true;
    this.KeyDown += RadForm1_KeyDown;
  
}
 
private void RadForm1_KeyDown(object sender, KeyEventArgs e)
{
    if (this.radPdfViewer1.Focused)
    {
        return;
    }
 
    if (e.KeyData == Keys.PageUp)
    {
        radPdfViewer1.PdfViewerElement.PageUp();
    }
    if (e.KeyData == Keys.PageDown)
    {
        radPdfViewer1.PdfViewerElement.PageDown();
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
LT
Top achievements
Rank 1
answered on 29 May 2019, 03:01 PM

Hello,

Scrolling up an entire page up and down isn't an issue, but I'd like to replicate scrolling with the mousewheel, so it would scroll up one line or two lines much like scrolling with the mouse wheel or pressing the Up and Down arrow keys (without having to be in focus). The methods .PageUp() and .PageDown() scroll entire pages.

 

0
LT
Top achievements
Rank 1
answered on 29 May 2019, 03:44 PM

https://www.telerik.com/forums/radscrollable-panel#WhBxorr4cUyrWbb8JmfGrA

An answer from another post helped me out.

If anyone comes across this post, here's what I did to stimulate scrolling. I was able to scroll in all directions without leaving another control's focus.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case (Keys.Up | Keys.Alt):
                case (Keys.Down | Keys.Alt):
                case (Keys.Left | Keys.Alt):
                case (Keys.Right | Keys.Alt):
                    ScrollPDFViewer(keyData);
                    break;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

 

        private void ScrollPDFViewer(Keys keyData)
        {
            RadScrollBarElement vScroll = this.radPdfViewer.PdfViewerElement.VScrollBar as RadScrollBarElement;
            RadScrollBarElement hScroll = this.radPdfViewer.PdfViewerElement.HScrollBar as RadScrollBarElement;
            switch (keyData)
            {
                case (Keys.Up | Keys.Alt):
                    vScroll.PerformSmallDecrement(1);
                    break;
                case (Keys.Down | Keys.Alt):
                    vScroll.PerformSmallIncrement(1);
                    break;
                case (Keys.Right | Keys.Alt):
                    hScroll.PerformSmallIncrement(1);
                    break;
                case (Keys.Left | Keys.Alt):
                    hScroll.PerformSmallDecrement(1);
                    break;
            }
        }

0
Dimitar
Telerik team
answered on 30 May 2019, 08:23 AM
Hi LT,

Thank you for sharing your solution. I have updated your Telerik Points.

Do not hesitate to contact us if you have other questions.

Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfViewer and PdfViewerNavigator
Asked by
LT
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
LT
Top achievements
Rank 1
Share this question
or