1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
public class MyTextBox : System.Windows.Forms.TextBox
{
public event EventHandler SelectionChanged;
private int _MySelStart = 0;
private int _MySelLength = 0;
private Timer tm;
public MyTextBox()
{
tm = new Timer();
tm.Interval = 250;
tm.Tick += new EventHandler(tm_Tick);
tm.Start();
}
~MyTextBox()
{
tm.Stop();
tm.Dispose();
}
void tm_Tick(object sender, EventArgs e)
{
CheckSelectionChanged();
}
private void CheckSelectionChanged()
{
if (SelectionLength != _MySelLength || (SelectionStart != _MySelStart && SelectionLength != _MySelLength))
OnSelectionChanged();
}
protected virtual void OnSelectionChanged()
{
if (SelectionChanged != null)
SelectionChanged(this, new EventArgs());
_MySelStart = SelectionStart;
_MySelLength = SelectionLength;
}
} |