hamze torabzade
hamze torabzade

Reputation: 7331

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';
        }
    }

Upvotes: 0

Views: 151

Answers (1)

digEmAll
digEmAll

Reputation: 57220

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?

Upvotes: 3

Related Questions