0 votes
by (650 points)
edited

I need to implement shortcuts to scroll in Telnet/SSH Terminal. How can I force scroll Up/Down (full page, half page and one line at a time) ?

Thank you

André Sanscartier

1 Answer

+1 vote
by (73.6k points)
edited
 
Best answer

There is no method for programmatic scrolling of TerminalControl in the current version, but you can use a workaround using OnMouseWheel method. It can be done like this:

public class MyTerminalControl : TerminalControl
{
    private const int WHEEL_DELTA = 120;

    /// <summary>
    /// Scrolls the control.
    /// </summary>
    /// <param name="rows">Number of rows to scroll.</param>
    public void Scroll(int rows)
    {
        MouseEventArgs e = new MouseEventArgs(0, 0, 0, 0, rows * WHEEL_DELTA);
        base.OnMouseWheel(e);
    }

    protected override void OnKeyDown(KeyEventArgs e)
    {
        int delta = 0;
        switch (e.KeyCode)
        {
            case Keys.PageUp:
                if (e.Control)
                    delta = 1;
                if (e.Shift)
                    delta = Screen.Rows;
                break;
            case Keys.PageDown:
                if (e.Control)
                    delta = -1;
                if (e.Shift)
                    delta = -Screen.Rows;
                break;
        }
        if (delta != 0)
        {
            Scroll(delta);
            return;
        }

        base.OnKeyDown(e);
    }
}

On the form use the MyTerminalControl instead of the TerminalControl. Now you are able to scroll by hitting Ctrl+PageUp/Down (one line) and by hitting Shift+PageUp/Down (one screen).

by (650 points)
edited

Great! Works like a charm :)

by (73.6k points)
edited

From version 2013 R1 (build number 4959), you can use public method Scroll(int rows).

...