Yong Sheng
Yong Sheng

Reputation: 1

button_Click(button, EventArgs.Empty);

it doesn't work when my i put this:

if(label.text != " ")
{
    btn_Click(btn, EventArgs.Empty);
}

private void btn_Click(obeject sender, EventArgs e)
{
    do something//
}

the button click function doesn't work

Upvotes: 0

Views: 472

Answers (3)

Try this:

if (label.text != " ")
{
    btn_Click(this, EventArgs.Empty);
}

private void btn_Click(obeject sender, EventArgs e)
{
    //do something//
}

Upvotes: -1

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

I think you mean not

label.Text != " "
               ^-------------- space

try this:

if(label.Text != string.Empty())
{
   .....
}

Upvotes: 0

Habib
Habib

Reputation: 223247

Its better if you can extract the code in the event to a separate method and then call that method, instead of raising the event.

private void btn_Click(obeject sender, EventArgs e)
{
  ExtractedMethod();
}

private void ExtractedMethod()
{
// do something
}

if(label.text != " ")
{
ExtractedMethod();
}

Upvotes: 4

Related Questions