weiszam
weiszam

Reputation: 187

Change scrollbar value while scrolling even if the Focus is on a different object

I have a textBox and a vScrollBar on a Form. I'd like the textBox to have focus, but when it does, using the Scroll button on the mouse won't change the scrollbar value. If the scrollbar has the focus, I can easily scroll with the mouse, but typing text in the textbox won't work then. Is there any way to catch all the scroll button activity on the form and redirect it to the scrollbar?

Upvotes: 0

Views: 747

Answers (2)

Go under the forms properties and add a KeyDown event, inside the event type:

yourTextBox.Text += e.KeyValue;

After that, go under the textbox properties and add an Enter event, inside the event type:

this.Focus();

Essentially what will happen is this. The form will now direct each keypress to the textbox. When the textbox is in focus, said textbox will unfocus itself letting the form append any characters to the textbox.

Upvotes: 0

Amol
Amol

Reputation: 119

Handle MouseWheel event of TextBox...

public frmSTOverScrollText()
{
    InitializeComponent();
    txtInput.MouseWheel += new MouseEventHandler(txtInput_MouseWheel);
}

void txtInput_MouseWheel(object sender, MouseEventArgs e)
{
    if (e.Delta < 0)
    {
        if (vsInput.Value + vsInput.LargeChange <= vsInput.Maximum)
            vsInput.Value += vsInput.LargeChange;
    }
    else if (vsInput.Value - vsInput.LargeChange >= vsInput.Minimum)
        vsInput.Value -= vsInput.LargeChange;
}

Upvotes: 1

Related Questions