本文介绍了记录最后一次鼠标点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我如何记录最后一次鼠标点击? 我有一个程序,我有一个名为red_balloon和green_balloon的图像。 我给用户点数取决于他们点击了气球顺序正确,red_balloon然后green_balloon。 如果订单不正确,他们会失去一分。 所以我需要一种记录最终点击的方法,是否有简单的方法。 这是我的代码到目前为止.. **代码XAML ** < 图像 高度 = 53 Horizo​​ntalAlignment = 左 保证金 = 0,0,0,0 x:名称 = red_balloon 拉伸 = 填写 VerticalAlignment = 顶部 宽度 = 48 来源 = red.png MouseLeftButtonDown = redballoon_click Canvas.Left = 194 Canvas.Top = 161 RenderTransformOrigin = 0.938,0.536 / > < 图片 高度 = 53 Horizo​​ntalAlignment = 左 保证金 = 0,0,0,0 x:名称 = green_balloon 拉伸 = 填写 VerticalAlignment = Top 宽度 = 48 来源 = gre en.png MouseLeftButtonDown = redballoon_click Canvas.Left = 194 Canvas.Top = 161 RenderTransformOrigin = 0.938,0.536 / > **代码c#** private void greenballoon_click( object sender,MouseButtonEventArgs e) { if (last_click == red_balloon) // 需要识别最后一次点击的方法是red_balloon { PopBalloonCount ++; } else { PopBalloonCount--; } 得分。内容= 您的分数 + + Convert.ToString(PopBalloonCount); } 解决方案 你可以使用hittest来获得合适的形状。 我这样做了: WPF-Drawing Canvas控制 [ ^ ] How would I record last mouse click ?I have a program where I have images called red_balloon and green_balloon.I give the user points depending if they click the balloons in the right order, red_balloon then green_balloon.If the order is not correct they loose a point.So I need a way to record last click, is there a simple way of doing this.Here is my code so far..**Code XAML** <Image Height="53" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="red_balloon" Stretch="Fill" VerticalAlignment="Top" Width="48" Source="red.png" MouseLeftButtonDown="redballoon_click" Canvas.Left="194" Canvas.Top="161" RenderTransformOrigin="0.938,0.536" /><Image Height="53" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="green_balloon" Stretch="Fill" VerticalAlignment="Top" Width="48" Source="green.png" MouseLeftButtonDown="redballoon_click" Canvas.Left="194" Canvas.Top="161" RenderTransformOrigin="0.938,0.536" />**Code c#** private void greenballoon_click(object sender, MouseButtonEventArgs e) { if (last_click =="red_balloon") // need a way to identify the last click was red_balloon { PopBalloonCount++; } else { PopBalloonCount--; } score.Content = "Your Score" + " " + Convert.ToString(PopBalloonCount); } 解决方案 You could use hittest to get the appropriate shape.I did so here:WPF-Drawing Canvas Control[^] 这篇关于记录最后一次鼠标点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 11:04