user2034477
user2034477

Reputation: 13

C# Window form text box contents have been highlighted event

is there an event for when the contents of a text box have been highlighted.

If not is there a way to determine this.

Also is there a way to determine of a text box has been tabbed to.

Thanks,

Upvotes: 1

Views: 1119

Answers (2)

Aniket Inge
Aniket Inge

Reputation: 25695

You will have to mix a few events for this.

  1. Capture Left Mouse button OR Shift Key+Arrow key
  2. MouseDrag event also must be captured after that
  3. Mouse Button Up too (for the next time).

Upvotes: 0

Simon Whitehead
Simon Whitehead

Reputation: 65069

There is no event for highlighting.. but you can simulate it via the MouseUp and KeyUp events:

private void textBox_MouseUp(object sender, MouseEventArgs e) {
    if (textBox.SelectedText != "")
        MessageBox.Show("Selected!");
}

private void textBox_KeyUp(object sender, KeyEventArgs e) {
    if (textBox.SelectedText != "")
        MessageBox.Show("Selected!");
}

There is also an Enter event for when the TextBox gains focus.

Upvotes: 3

Related Questions