单击c#删除对象

时间:2014-03-25 11:51:58

标签: c# silverlight xaml object mouseevent

我有一些用户可以点击的对象,一旦点击那里就会显示一个消息框,一旦此消息框之后想要删除该对象。

有一种简单的方法吗?

我的代码

private void redballoon_click(object sender, MouseButtonEventArgs e)
{
    string red_balloon_question = System.Windows.Browser.HtmlPage.Window.Prompt("Question 5X2");

    if (red_balloon_question == "10")
    {
        MessageBox.Show("Well done that is correct, you gain 1 point", "Correct Answer", MessageBoxButton.OK);
        PopBalloonCount++;             
    }
    else
    {
        MessageBox.Show("Incorrect, you loose 1 point", "Wrong Answer", MessageBoxButton.OK);
        PopBalloonCount--;
    }

    score.Content = "Your Score" + " " + Convert.ToString(PopBalloonCount);
    this.lastBalloonClickColor = "red_balloon"; // register the last click
} 

XMAL代码

MouseLeftButtonDown="redballoon_click"

所以一旦消息框消失,我希望删除red_balloon,让任何人都知道如何做到这一点?

1 个答案:

答案 0 :(得分:0)

您应该尝试以下代码:

private void redballoon_click(object sender, MouseButtonEventArgs e)
{
    //react only when baloon is clicked by left mouse button
    if (e.LeftButton != MouseButtonState.Pressed)
        return;

    string red_balloon_question = System.Windows.Browser.HtmlPage.Window.Prompt("Question 5X2");

    if (red_balloon_question == "10")
    {
        MessageBox.Show("Well done that is correct, you gain 1 point", "Correct Answer", MessageBoxButton.OK);
        PopBalloonCount++;             
    }
    else
    {
        MessageBox.Show("Incorrect, you loose 1 point", "Wrong Answer", MessageBoxButton.OK);
        PopBalloonCount--;
    }

    score.Content = "Your Score" + " " + Convert.ToString(PopBalloonCount);
    this.lastBalloonClickColor = "red_balloon"; // register the last click

    //hide baloon
    redballoon.Visibility = Visibility.Hidden;
    //or
    redballoon.Opacity = 0.0;
}