jeudi 1 janvier 2015

C# checking which imagebox is clicked (onMouseUp)

I want to check which of the 3 image boxes is clicked. I tried using if(leftImage.mouseUp == true) but that does not work and returns a syntax error. So my question is, how do you check if an image is clicked in an if statement.



public int currentQuestion = 0;

public void ImageCheck ()
{
int[] ImageValues = new int[15];
ImageValues[0] = 1;
ImageValues[1] = 2;
ImageValues[2] = 3;
ImageValues[3] = 4;
ImageValues[4] = 5;
ImageValues[5] = 6;
ImageValues[6] = 7;
ImageValues[7] = 8;
ImageValues[8] = 9;
ImageValues[9] = 10;
ImageValues[10] = 11;
ImageValues[11] = 12;
ImageValues[12] = 13;
ImageValues[13] = 14;
ImageValues[14] = 15;

Random randomize = new Random();
int initialValue = randomize.Next(0, 4);
int finalValue = ImageValues[initialValue];


if(finalValue == 1)
{
leftImagebox.Source = new BitmapImage(new Uri(@"projectImages\triangle.png", UriKind.RelativeOrAbsolute));
midImagebox.Source = new BitmapImage(new Uri(@"projectImages\circle.png", UriKind.RelativeOrAbsolute));
rightImagebox.Source = new BitmapImage(new Uri(@"projectImages\square.png", UriKind.RelativeOrAbsolute));
question.Content = "Kan jij de driehoek aanwijzen?";

vraag.Margin = new Thickness(425, 40, 0, 0);

aantal.Margin = new Thickness(590, 40, 0, 0);

question.Margin = new Thickness(205, 112, 0, 0);

currentQuestion = 1;
}

else if(finalValue == 2)
{
leftImagebox.Source = new BitmapImage(new Uri(@"projectImages/middelstestaaf.png", UriKind.RelativeOrAbsolute));
midImagebox.Source = new BitmapImage(new Uri(@"projectImages/kortestaaf.png", UriKind.RelativeOrAbsolute));
rightImagebox.Source = new BitmapImage(new Uri(@"projectImages/langestaaf.png", UriKind.RelativeOrAbsolute));
question.Content = "Kan jij de dunste staaf aanwijzen?";

vraag.Margin = new Thickness(425, 40, 0, 0);

aantal.Margin = new Thickness(590, 40, 0, 0);

question.Margin = new Thickness(170, 112, 0, 0);

midImagebox.Margin = new Thickness(500, 242, 0, 0);

rightImagebox.Margin = new Thickness(815, 242, 0, 0);

currentQuestion = 2;
}

else if (finalValue == 3)
{
leftImagebox.Source = new BitmapImage(new Uri(@"projectImages\triangle.png", UriKind.RelativeOrAbsolute));
midImagebox.Source = new BitmapImage(new Uri(@"projectImages\square.png", UriKind.RelativeOrAbsolute));
rightImagebox.Source = new BitmapImage(new Uri(@"projectImages\circle.png", UriKind.RelativeOrAbsolute));
question.Content = "Kan jij de cirkel aanwijzen?";

vraag.Margin = new Thickness(435, 40, 0, 0);

aantal.Margin = new Thickness(600, 40, 0, 0);

question.Margin = new Thickness(245, 112, 0, 0);

midImagebox.Margin = new Thickness(470, 242, 0, 0);

currentQuestion = 3;
}

}



public void inputCheck ()
//cant seem to work out the code here to check if the imagebox is selected while on the specific question.
{
if (currentQuestion == 1 && leftImagebox.MouseUp == true)
{

}
}

private void leftImagebox_MouseUp(object sender, MouseButtonEventArgs e)
{

}
}

Aucun commentaire:

Enregistrer un commentaire