mercredi 28 janvier 2015

Store two mouse click positions on canvas when checkbox enabled

I have a checkbox at the moment where, when I click it, it should allow the user to click two places on a canvas, and then a messagebox with the coordinates of both clicks appear, and then the checkbox should uncheck itself. I've tried various things and keep running into a few problems.



  1. Checking the box is a RoutedEventArgs where as clicking on the canvas is a MouseButtonEventArgs.

  2. I'm unable to store the second mouse click (the first click appears twice); I've tried various for loops, while loops, etc.

  3. I'm unable to get the box to uncheck itself after the message box appears, regardless of where I put the .Checked == false. I get an error that says system.windows.etcetc.checked can only appaer on the left hand side of += or -=.


I'd like to handle the whole thing in a function related to the checkbox aka the routedeventargs and not a canvas click method.


I can figure out #2 but 1 and 3 have me stumped.


This is a sample of the method which is subscribed to from a canvas mousedown in the xaml:



public void get_Scaling(object sender, MouseButtonEventArgs e)
{
Point startPoint;
Point endPoint;

while (Scale_btn.IsChecked == true)
{
startPoint = e.GetPosition(canvas1);

endPoint = e.GetPosition(canvas1);

System.Windows.MessageBox.Show("Start point is" + startPoint + "and end point is" + endPoint, "test", MessageBoxButton.OK, MessageBoxImage.Information);
}
}




Aucun commentaire:

Enregistrer un commentaire