简体   繁体   English

如何知道在 C# 中触摸/点击了哪个图像(移动编码)

[英]How to know which image is touched/clicked in C# (mobile Coding)

I am very new to C#.我对 C# 很陌生。 Now my situation is I have two different images, how do I know that which one is clicked/touched by user?现在我的情况是我有两个不同的图像,我怎么知道用户点击/触摸了哪一个? Can I have both coding for clicked and the touched coding?我可以同时进行点击编码和触摸编码吗?

void Update () { 
   for (int i = 0; i < Input.touchCount; i++) { 
         if (imageA.transform.position.x == Input.GetTouch (i).position.x && imageA.transform.position.y == Input.GetTouch(i).position.y) { 
               textA.text = "Hello";
             } 
    } 
} 

Whenever you click a image the object sender which is a parameter of the event fired gives you the information.每当您单击图像时,作为触发事件参数的object sender都会为您提供信息。 You can cast it to type from which it is sent and it contains all the data .您可以将其转换为发送它的类型,并且它包含所有数据。

private void Image_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Image image = sender as Image;
            //image is your image control and it has all its properties set
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM