I try to press button hold and this type of error occurred. Short Press work better but while press long (Cross-thread operation not valid: Control 'panel' accessed from a thread other than the thread it was created on.) this type of error occurred.
What I have tried:
loopTimer = new Timer();
loopTimer.Interval = 1000;
loopTimer.Enabled = false;
loopTimer.Elapsed += loopTimerEvent;
loopTimer.AutoReset = true;
public bool long_press = false;
private void loopTimerEvent(object source, ElapsedEventArgs e)
{
loopTimer.Dispose();
long_press = true;
panel_animatedOrders.Show();
}
public void newdowntable_Click(object sender, MouseEventArgs e)
{
loopTimer.Enabled = true;
label1.Text = ((Button)sender).Name;
btn_one.Text = ((Button)sender).Name + " " + "A";
btn_two.Text = ((Button)sender).Name + " " + "B";
btn_three.Text = ((Button)sender).Name + " " + "C";
btn_four.Text = ((Button)sender).Name + " " + "D";
k_one.Text = ((Button)sender).Name + ".1";
k_two.Text = ((Button)sender).Name + ".2";
k_three.Text = ((Button)sender).Name + ".3";
k_four.Text = ((Button)sender).Name + ".4";
btn_kitchenOrderNumber.Text = ((Button)sender).Name;
}
public void newupTable_Click(object sender, MouseEventArgs e)
{
loopTimer.Enabled = false;
if (long_press==false)
{
label1.Text = ((Button)sender).Name;
Control ctls = this.Parent;
KOTOrder vieret = new KOTOrder(label1.Text, btn_kitchenOrderNumber.Text);
ctls.Controls.Clear();
ctls.Controls.Add(vieret);
}
long_press = false;
}