S
Shane Poppleton via .NET 247
I am trying to capture the current line and current column position in a text box, i have successfully created a function that returns the line and column number for display in the status bar e.g.
"Ln 2 Col 5", but when do i fire it, i at first tried the TextChanged event, but unfortunately the line and col number is only right when someone is changing the text, if up, down, left, right, home, end, page down or page up is pressed it doesn't update.
I have also tried the KeyDown Event, but the event get fired before the cursor moves so the display is always wrong. I thought a solution was to use the following code.
string key;
switch (e.KeyData)
{
case Keys.Up:
key="{UP}";
break;
/// Etc., etc.
}
if (key!=null)
{
SendKeys.Send(key);
e.Handled = true;
}
statusBar1.Text = GetPosition(textBox1);
But it still doesn't work, any ideas.
"Ln 2 Col 5", but when do i fire it, i at first tried the TextChanged event, but unfortunately the line and col number is only right when someone is changing the text, if up, down, left, right, home, end, page down or page up is pressed it doesn't update.
I have also tried the KeyDown Event, but the event get fired before the cursor moves so the display is always wrong. I thought a solution was to use the following code.
string key;
switch (e.KeyData)
{
case Keys.Up:
key="{UP}";
break;
/// Etc., etc.
}
if (key!=null)
{
SendKeys.Send(key);
e.Handled = true;
}
statusBar1.Text = GetPosition(textBox1);
But it still doesn't work, any ideas.