Reputation: 1
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
Reputation: 1
Try this:
if (label.text != " ")
{
btn_Click(this, EventArgs.Empty);
}
private void btn_Click(obeject sender, EventArgs e)
{
//do something//
}
Upvotes: -1
Reputation: 33381
I think you mean not
label.Text != " "
^-------------- space
try this:
if(label.Text != string.Empty())
{
.....
}
Upvotes: 0
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