One solution would be to use the MouseMove event of the component.
Then focus the sender of the event ( which should be the component ).
Just tried it with textBoxes but it should work with every component normally.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GUITestC {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.fillTxtBoxes(this.txtBoxLeft, this.txtBoxRight);
}
private void fillTxtBoxes(params TextBox [] ar) {
foreach (TextBox txtBox in ar) {
for (int i = 0; i < 100; i++) {
txtBox.AppendText(i + "\r\n");
}
}
}
private void txtBoxRight_MouseMove(object sender, MouseEventArgs e) {
TextBox b = (TextBox)sender;
b.Focus();
}
private void txtBoxLeft_MouseMove(object sender, MouseEventArgs e) {
TextBox b = (TextBox)sender;
b.Focus();
}
}
}
Where txtBoxRight and left are multiline textboxes with a vertical scrollbar. When hovered over the textbox it will be focussed, thus enabling you to scroll when you hover over it .
:edit:
I guess you could also use the MouseLeave event to focus the main form or whatever you want to give default focus when the mouse is no longer over the component.
:edit 2:
Next time you want to clarify your question , please do this in the same thread, or edit your post in that thread. Else this whole board would be flooded with threads that don't make any sense.