Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to Zoom In/Out with help of +/ - Key press (Read 2053 times)
suchit_sapate
YaBB Newbies
*
Offline


Hi Everybody !!!!!!!!!!

Posts: 5
Joined: Apr 3rd, 2009
How to Zoom In/Out with help of +/ - Key press
Apr 3rd, 2009 at 1:37pm
Print Post  
How to add key press events?
How to regnize the key code?
How to Zoom In/out the diagram with the help of +/- Key ?                     
  

Suchit Sapate&&Persistent Systems Ltd.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to Zoom In/Out with help of +/ - Key press
Reply #1 - Apr 6th, 2009 at 9:52am
Print Post  
Code
Select All
<ScrollViewer Focusable="False" ...
<Diagram KeyDown="OnDiagramKeyDown" ...

private void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.OemPlus)
		diagram.ZoomIn();
	else if (e.Key == Key.OemMinus)
		diagram.ZoomOut();
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
suchit_sapate
YaBB Newbies
*
Offline


Hi Everybody !!!!!!!!!!

Posts: 5
Joined: Apr 3rd, 2009
Re: How to Zoom In/Out with help of +/ - Key press
Reply #2 - Apr 6th, 2009 at 10:02am
Print Post  
I am new in WPF.
I didn't know how to zoom in and zoom out the function.
private void diagram_KeyDown(object sender, KeyEventArgs e)
       {
if (e.Key.Equals(System.Windows.Input.Key.Add))
           {               
               e.Handled = true;
               diagram.ZoomFactor += 2;               
           }
           if (e.Key.Equals(System.Windows.Input.Key.Subtract))
           {
               if ((diagram.ZoomFactor - 2) > 0 && diagram.ZoomFactor > 10)
               {                  
                   e.Handled = true;
                   diagram.ZoomFactor += -2;                      }
               else
               {
                   e.Handled = true;
                   return;
               }
           }
           if((e.Key.Equals(System.Windows.Input.Key.Add))||(e.Key.Equals(System.Windows.In
put.Key.Subtract)))
           {
               CreateCanvas();
           }
         
       }
       private void CreateCanvas()
       {
           Rect newBounds = diagram.ClientToDoc(
           new Rect(0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight));

                 newBounds.Union(diagram.GetContentBounds(false, false));
           newBounds.Inflate(200, 200);
           diagram.Bounds = newBounds;
       }
I write following code but it didn't work properly it has some issue in Zoom in like It shift the image right to left in zoom in.
But i reqired it grows at the center of image.
  

Suchit Sapate&&Persistent Systems Ltd.
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint