How do I use the page-up/down and arrow keys to scroll a Diagram

I can scroll my Diagram with the mouse wheel or via the overview control.  I would also like to provide scroll capability from wither the page-up/down or arrow keys on the keyboard.

1 Reply

NG Naganathan Ganesh Babu Syncfusion Team September 21, 2015 06:12 AM UTC

Hi John,

 

In order to achieve your requirement, override the “ProcessCmdKey” method and change the Diagram.View’s “Origin”, as well as “ScrollVirtualBounds.Location” values while pressing the page Up/Down keys. Please refer to the below code example and sample.


 

Code Example:


 

[C#]


 

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

{

PointF origin = diagram1.View.Origin;

PointF virtualTopLeft = diagram1.View.ScrollVirtualBounds.Location;

if (keyData == Keys.PageDown)

{

origin.Y += 10;

virtualTopLeft.Y -= 10;

}

if (keyData == Keys.PageUp)

{

//down                 

origin.Y -= 10;

}

//remove the unnecessary gray area at top-left when move the diagram towards left and top

diagram1.View.ScrollVirtualBounds = new RectangleF(virtualTopLeft, diagram1.View.ScrollVirtualBounds.Size);

diagram1.View.Origin = origin;  

return base.ProcessCmdKey(ref msg, keyData);

}


 

Sample:

 

Sample


 

Regards,


 

Naganathan K G


Loader.
Up arrow icon