Created
September 3, 2011 03:47
-
-
Save akfish/1190519 to your computer and use it in GitHub Desktop.
C# Get active TextBox and insert text at cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (this.ActiveControl.GetType() == typeof(TextBox)) | |
{ | |
TextBox textBox = (TextBox)this.ActiveControl; | |
String text = ((Label)sender).Text; | |
int pos = textBox.SelectionStart; | |
textBox.Text = textBox.Text.Insert(pos, text); | |
//Fix cursor position | |
textBox.Focus(); | |
textBox.SelectionStart = pos; | |
textBox.SelectionLength = text.Length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment