2
Reply

Get focused

cory thompson

cory thompson

Jan 9 2012 5:23 PM
1.9k
Hi guys, I'm trying to get the focused textbox so I can insert a time stamp, the code below will put a timestamp into textBox1 but I dont want to define the textbox so i'm looking for something like "focused.text" instead of "textBox1.text".
Can anyone help with this
Thanks.


  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  {
  switch (keyData)
  {
  case Keys.Control | Keys.T:
  var insertText = DateTime.Now.ToString();
  var selectionIndex = textBox1.SelectionStart;
  textBox1.Text = textBox1.Text.Insert(selectionIndex, insertText);
  textBox1.SelectionStart = selectionIndex + insertText.Length;
  return true;
  }
  return false;
  }

Answers (2)