Pregunta

I am trying to figure out how to make it that when my timer ticks, it performs a bidder00_TextChanged, or something like that.

Is this even possible to do? and if it isn't, is there any other way to do it? I tried to search Google for it but i didn't get any results, if you find anything that i missed please post it here.

I don't really have any code but here it is:

private void bidder00_TextChanged(object sender, EventArgs e)
{
    if (bidder00.Text == addbidder1.Text)
    {
        bidBtn1.PerformClick();
    }
}

That is my TextChanged Event

My timer doesn't have any code because it is going to perform the bidder00_TextChanged Event.

¿Fue útil?

Solución

You could create a method Perform() and call it from within your event handlers :

private void timer1_Tick(object sender, EventArgs e)
{
   Perform();
}

private void bidder00_TextChanged(object sender, EventArgs e)
{
   Perform();
}

private void Perform()
{
   if (bidder00.Text == addbidder1.Text)
   {
      bidBtn1.PerformClick();
   }
}

Otros consejos

I assume you have coupled your actual logic with your click event which is not a good idea. Separate the code out into a separate function and have both parts of the application call the same code e.g.

private void SubmitBid()
{
    // code you want to execute
}

private void OnSubmitBid()
{
     // confirm whether we can actually submit the bid
     if (bidder00.Text == addbidder1.Text)
     {
          SubmitBid();
     }
}

private void Timer1_OnTick(object sender, EventArgs e)
{
    // trigger code from timer
    OnSubmitBid();
}

private void bidder00_TextChanged(object sender, EventArgs e)
{
    // trigger code from text change
    OnSubmitBid();
}

private void btnBid_Click(object sender, EventArgs e)
{
    // trigger code from button press
    OnSubmitBid();
}

Notice all the UI controls trigger the same code. There is an extra call in there for the text control validation (i.e. OnSubmitBid()) - if this wasn't required then you would just call SubmitBid directly.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top