# Disabling Rotate and Zoom in vtkInteractorStyleImage

**URL:** https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327
**Category:** Support
**Created:** [September 30, 2020, 8:32pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327 "2020-09-30T20:32:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![frenchnq](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@frenchnq](https://discourse.vtk.org/u/frenchnq)
#### Post date: [September 30, 2020, 8:32pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/1 "2020-09-30T20:32:18Z")

</div>

I’m working on a C# window forms project and trying to disable the zoom and rotate methods of my rendered window. I’m currently using the vtkInteractorStyleImage for my interactor, but haven’t been successful in overriding the inherited methods. Any easy ways to just turn zoom and rotate off so that I’m only able to pan?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [September 30, 2020, 9:19pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/2 "2020-09-30T21:19:39Z")

</div>

What have you tried so far? It should be possible to override the interaction by adding observers for `RightButtonPressEvent`, `LeftButtonPressEvent`, and `MiddleButtonPressEvent`.

---

<div class="post-metadata">

### Author: ![frenchnq](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@frenchnq](https://discourse.vtk.org/u/frenchnq)
#### Post date: [October 1, 2020, 2:39pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/3 "2020-10-01T14:39:34Z")

</div>

I’ve tried to make a derived class from vtkInteractorStyleImage and then initialize from that class.

For Example:  
class DerivedClass : vtkInteractorStyleImage  
{  
public override void OnLeftButtonDown()  
{  
Console.Write(“test”);  
}

```
    public override void OnMiddleButtonDown()
    {
        Console.Write("test");
    }

    public override void OnRightButtonDown()
    {
        Console.Write("test");
    }
}

```

The initialize doing:  
vtkInteractorStyleImage interactorstyle = new DerivedClass();

I just tried following your suggestion partly where I was able to disable the scrolling zoom by doing:  
interactorstyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(DoNothing);  
interactorstyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(DoNothing);  
where DoNothing is an empty method.

However, what would I do for the mouse press events? The shift key and control key are both still needed when the left button is down to pan and rotate, respectively.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 1, 2020, 3:00pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/4 "2020-10-01T15:00:33Z")

</div>

To disable certain events by adding event handlers, your handler needs to do this:

1. call intertactorstyle.GetInteractor() to check whether shift or control was used
2. if the button and modifiers are for an action you want to cancel, then return without doing anything
3. if the button and modifiers are for an action you want to keep, then call interactorstyle.OnLeftButtonDown() (or Middle or Right) and the action will be taken

---

<div class="post-metadata">

### Author: ![frenchnq](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@frenchnq](https://discourse.vtk.org/u/frenchnq)
#### Post date: [October 1, 2020, 10:34pm UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/5 "2020-10-01T22:34:19Z")

</div>

Thanks a lot, this mostly works. Here’s the code that I have set up:

In the interactor style definition:  
interactorstyle.LeftButtonPressEvt += new vtkObject.vtkObjectEventHandler(DoSomething);

where DoSomething is:  
private void DoSomething(vtkObject sender, vtkObjectEventArgs e)  
{  
vtkRenderWindow window = renderWindowControl1.RenderWindow;  
vtkRenderWindowInteractor interactor = window.GetInteractor();

```
        interactor.SetAltKey(0);
        interactor.SetControlKey(0);
        interactor.SetShiftKey(4);

        vtkInteractorStyleImage interactorstyle = (vtkInteractorStyleImage)interactor.GetInteractorStyle();
        interactorstyle.OnLeftButtonDown();
    }

```

This mostly works, because it lets me pan by just left click and drag and no other features are enabled. However, I occasionally get the following error:

An unhandled exception of type ‘System.Exception’ occurred in Kitware.mummy.Runtime.dll  
Additional information: error: could not get registered type - mteIndex=‘4294967295’ classNameKey=’’

Any idea as to something I should be doing differently?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 2, 2020, 12:40am UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/6 "2020-10-02T00:40:26Z")

</div>

Oh, definitely do not call SetAltKey(), SetControlKey(), SetShiftKey(). Instead, call GetAltKey(), GetControlKey() and GetShiftKey(). The goal is to check the values of these modifiers, not to set them.

---

<div class="post-metadata">

### Author: ![frenchnq](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ac91a4/32.png) [@frenchnq](https://discourse.vtk.org/u/frenchnq)
#### Post date: [October 2, 2020, 1:29am UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/7 "2020-10-02T01:29:04Z")

</div>

Yes, that’s originally what I had to only check if GetShiftKey() was != 0 to call OnLeftButtonDown(). However, an even better solution would be to have the pan happen anytime the left button was used regardless of key press, which is why I chose to set the keys.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [October 2, 2020, 2:01am UTC](https://discourse.vtk.org/t/disabling-rotate-and-zoom-in-vtkinteractorstyleimage/4327/8 "2020-10-02T02:01:05Z")

</div>

I guess it’s okay if that’s what you want to do. As for me, I would worry about changing the state variables of the interactor while an event is still ongoing.

For the exception I can only make a wild guess, since I’m not a C# programmer.
