how add a string to focused texbox in winform c#
I want to add a char to focused texbox in winform c#
. how can i do that ? actually i want control e.KeyChar
in myform_KeyPress
event.
private void add_user_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\r' && hidden_scan_textbox.Text != "")
{
开发者_运维问答 shomare_shenasai_view.Text = hidden_scan_textbox.Text;
hidden_scan_textbox.Text = "";
}
if (e.KeyChar != '\r')
{
hidden_scan_textbox.Text += e.KeyChar;
//here i want to add e.KeyChar to focused texbox
e.KeyChar = '\0';
}
}
myFormInstance.ActiveControl
returns the current focused control in the form.
Be careful because it could (depending on how your form is built) also be another control and not a textbox.
Have also a look at here: What is the preferred way to find focused control in WinForms app?
精彩评论