So... The user has to click on the button, after he clicks it, the program should wait for another click on Panel and get the coordinates of that click. But as soon as I click the button, everything becomes unresponsive. Am I doing something wrong?
private void Surbutton_Click(object sender, EventArgs e)
{
panel1.Cursor = Cursors.Cross;
Cursor.Position = new Point(Left + panel1.Left + panel1.Width / 2, Top + panel1.Top + panel1.Height / 2);
ziskavanie_pozicie = true;
//Button ABCD = sender as Button;
string ABCD = ((Button)sender).Name;
switch (ABCD)
{
case "button_A":
//cakaj.WaitOne();
cakaj_manual.WaitOne();
suradnica_Ax.Text = x.ToString();
suradnica_Ay.Text = x.ToString();
break;
case "button_B":
suradnica_Bx.Text = x.ToString();
suradnica_By.Text = x.ToString();
break;
case "button_C":
suradnica_Cx.Text = x.ToString();
suradnica_Cy.Text = x.ToString();
break;
case "button_D":
suradnica_Dx.Text = x.ToString();
suradnica_Dy.Text = x.ToString();
break;
}
}
public void panel1_MouseClick(object sender, MouseEventArgs e)
{
MessageBox.Show("Hehe");
if (ziskavanie_pozicie == true)
{
x = e.X;
y = e.Y;
//panel1.PointToClient(Cursor.Position);
ziskavanie_pozicie = false;
panel1.Cursor = Cursors.Default;
//cakaj.Set();
cakaj_manual.Set();
}
}
If you just want to know for the reason your programs freezes, It's because you using for some reason the
which are not expected to be used on the main thread as it's not the reason they created for. If you say for example
manualResetEvent.WaitOne();
on the main thread, everything will freeze. They are just made for synchronizing threads just likeMutex, Semphores, TPL->Await
etc..