nikorio
nikorio

Reputation: 691

How to run event implementation from other event condition

I'm wondering, if is it possible to run if (e.KeyCode == Keys.Enter) event process without pressing on enter, correctly to say without event condition itself.

The only way I know to get result, which can be useful if implemented, is to locate content of condition in function, but I'm asking if it is possible other way.

From textBox2_TextChanged event condition to get implementation of if (e.KeyCode == Keys.Enter) event of textBox1_KeyDown with entering of exist text and containing process implementation?

For example:

private void textBox1_KeyDown(object sender, KeyEventArgs e) 
{
   /// code  

   if (e.KeyCode == Keys.Enter)  
   {
      label1.Text = ("text inserted"); 
   }
}

and desired result is to call (e.KeyCode == Keys.Enter) implementation with label1.Text = ("text inserted"); from textBox1_KeyDown in textBox2_TextChanged here:

private void textBox2_TextChanged(object sender, EventArgs e)
{
    if (x > 0)
    {
       /// here I want implement if (e.KeyCode == Keys.Enter) from code above with label1.Text = ("text inserted");      
    }
}

Upvotes: 0

Views: 72

Answers (1)

Bakri
Bakri

Reputation: 707

you can like this

private void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            label1.Text = ("text inserted");
        }

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {
        KeyEventArgs ev = new KeyEventArgs(Keys.Enter);
        textBox1_KeyDown(sender, ev);
    }

Upvotes: 2

Related Questions