Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help (Read 4795 times)
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Feb 5th, 2020 at 11:40pm
Print Post  
Hello, I am trying to Pan (and scroll) the diagram using combination of the keyboard's 'C' key and mouse middle button (instead of mouse left). How to achieve that!?

The things that i tried:
1. Pressing keyboard (diagram.KeyDown += OnDiagmKeyDown) and switching the Behavior to Pan. But here we have to use mouse left button to move the view.

2. The Keyboard.Modifiers == ModifierKeys.Alt  doesn't have other key's option  Huh.

Please help. Thanks a ton
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #1 - Feb 6th, 2020 at 7:20am
Print Post  
Hi,

Setting diagram.MiddleButtonActions = MouseButtonActions.Pan will let you pan with middle button. If you need to allow that only with C key down, try toggling the property value from KeyDown/Up event handlers.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #2 - Feb 6th, 2020 at 5:37pm
Print Post  
@Slavcho thanks for your response.

I am trying to achieve a combination of Mouse Middle Down and C (key) to pan and Scroll on diagram.

As you suggested, yes
diagram.MiddleButtonActions = MouseButtonActions.Pan will change the diagram mode to Pan. But we still have to use mouse left button to scroll the diagram, which i am trying to achieve using Mouse Middle button only!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #3 - Feb 6th, 2020 at 7:04pm
Print Post  
I'm not sure if I follow Smiley MiddleButtonActions = Pan lets you pan with middle button, and is not one of the properties you meantioned trying in first post. Or do you mean you also want to use ScrollViewer's scrollbars with the middle button and prevent left-button-dragging them?
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #4 - Feb 6th, 2020 at 7:37pm
Print Post  
Usually, if we do diagram.Behavior  = Behavior.Pan, and press the left mouse button the cursor changes to a scroll cursor (something like <^> ).
Can we achieve the same thing (switching mode to Pan and scroll cursor) using
Keyboard.C (is continuously pressed) && Mouse.MiddleButtonPressed
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #5 - Feb 6th, 2020 at 7:55pm
Print Post  
try this -

Code
Select All
private void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	if (e.Key == Key.C)
	{
		// anything but Pan to prevent left-button pan
		diagram.Behavior = Behavior.DoNothing;

		// enable middle-button drag
		diagram.MiddleButtonActions = MouseButtonActions.Pan;
	}
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #6 - Feb 6th, 2020 at 9:52pm
Print Post  
@Slavcho Thanks for the quick insight. That worked.  Smiley
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #7 - Feb 6th, 2020 at 11:10pm
Print Post  
Based on the solution above, my use case is stuck again:
1. When C key is continuously pressed & along with it when mouse (with middle pressed) is moved then no notification is needed on UI.
2. When only C key is pressed and released a notification is needed on UI.

To do that, i tried to attached OnMouseDown handler to update a local property, but continuously pressing C key will Not allow OnMouseDown's handler to execute.


Example:

bool wasMouseUsedtoPan;

private void OnMouseDown(object sender, MouseButtonEventArgs e)
    {
//doesn't come here
if (e.MiddleButton == MouseButtonState.Pressed)
   wasMouseUsedtoPan= true;
}


internal void OnDiagramKeyDown(object sender, KeyEventArgs e)
      {
      if (e.Key == Key.C)
      {       
        diagram.Behavior = Behavior.DoNothing;
        diagram.MiddleButtonActions = MouseButtonActions.Pan;
}
}

I was also thinking it in this way; If we pan and scroll the diagram what property (like viewport! etc) of the diagram changes so that i can attached my event with that accordingly!

Thanks a lot.

« Last Edit: Feb 7th, 2020 at 12:16am by MikeHeal »  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #8 - Feb 7th, 2020 at 7:16am
Print Post  
What UI element have you attached that OnMouseDown handler to? This seems to work well enough in my test even with C held down -

Code
Select All
diagram.MouseDown += (ss, ee) =>
{
	Debug.WriteLine("mouse down");
	Debug.WriteLine(ee.MiddleButton);
	Debug.WriteLine(ee.ButtonState);
	Debug.WriteLine(ee.ChangedButton);
}; 



output is as follows for the three buttons -

Code
Select All
mouse down
Released
Pressed
Left
mouse down
Pressed
Pressed
Middle
mouse down
Released
Pressed
Right 



You can detect changed scroll position by handling the ScrollViewer.ScrollChanged event.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
MikeHeal
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 20
Joined: Feb 5th, 2020
Re: Diagram Pan (and move view) using a keyboard key and mouse middle button. Please help
Reply #9 - Feb 7th, 2020 at 8:36pm
Print Post  
@Slavcho: That helped. Its working perfectly now . Thanks for your time and patience  Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint