Skip to content

ALT+ScrollWheel causes loss of focus #436

Closed

Description

@tomwimmenhove

Describe the bug
After you zoom vertically, using alt+scroll-wheel, zooming horizontally using ctrl+scroll-wheel doesn't work, until the user clicks in, or pans the graph.

To Reproduce
Press alt and scroll to zoom in/out vertically. Release alt, then press ctrl and scroll to zoom horizontally. => You'd expect the graph to zoom horizontally, but nothing happens.

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            double[] dataX = new double[] { 1, 2, 3, 4, 5 };
            double[] dataY = new double[] { 1, 4, 9, 16, 25 };
            formsPlot1.plt.PlotScatter(dataX, dataY);
            formsPlot1.Render();
        }
    }

Activity

  1. StendProg commented on May 28, 2020

    @StendProg
    Contributor

    Hi @tomwimmenhove

    This problem is caused by a system event that causes the control to lose focus on Alt key press.
    I made PR that fixes this (#437).

    If you want a fast solution you can disable main menu of Form in your application by setting Form.ControlBox property to false.

    Also, loss of focus occurs on an odd Alt press. Each even Alt press returns focus...

  2. swharden commented on May 30, 2020

    @swharden
    Member

    Hi @tomwimmenhove thanks for reporting this, and @StendProg thanks for figuring out the cause of this issue!

    @StendProg's solution (#437) fixes the problem on the WinForms control (but it's still present on the WPF control).

    An alternative solution here may be to stop using the ALT key. Perhaps CTRL could lock the vertical axis and SHIFT could lock the horizontal axis. Currently SHIFT-click-drag is used to zoom-to-rectangle, but we could give that function to ALT, or even CTRL+SHIFT...

    Another alternative option may be to have mousewheel events create call a method to focus the control 50 ms after the wheel event. I'm not sure if this is possible yet. Something like:

    Task.Delay(50).ContinueWith(t=> GetFocusAgain());
  3. changed the title [-]Horizontal zoom not working after vertical zooming[/-] [+]ALT+ScrollWheel causes loss of focus[/+] on May 31, 2020
  4. swharden commented on May 31, 2020

    @swharden
    Member

    I think the best long-term solution here is to avoid using ALT in combination with scroll-wheel actions. ALT can be used with click-drag actions because the control maintains focus. Switching the function of ALT and SHIFT for the WinForms and WPF controls is probably the way to go here. The new list of actions is:

    • Left-click-drag: pan
    • Right-click-drag: zoom
    • Middle-click-drag: zoom region
    • ALT+Left-click-drag: zoom region
    • Scroll wheel: zoom to cursor
    • Right-click: show menu
    • Middle-click: auto-axis
    • Double-click: show benchmark
    • Hold CTRL to lock vertical axis
    • Hold SHIFT to lock horizontal axis

    We might want to consider adding CTRL+SHIFT+right-click-drag as a way to zoom without distorting the ratio (something you currently have to set with Configure(equalAxes: true), #306)

  5. swharden commented on May 31, 2020

    @swharden
    Member

    In addition to fixing the original issue, CTRL+SHIFT+right-click-drag now zooms evenly (with a fixed axis ratio). This feels really natural, I like it!

    Thanks for initially reporting this @tomwimmenhove and @StendProg for your helpful PR and research into message handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BUGunexpected behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions