简体   繁体   English

如何查找鼠标单击是否在wf面板中呈现的图像上?

[英]How to find if mouse click is on an image rendered in a wf panel?

First let me say I love this site and often find the answers to my questions before I ever have to post. 首先让我说我喜欢这个网站,并经常在我发布之前找到我的问题的答案。 Now I have a question that I can't seem to find an answer to. 现在我有一个问题,我似乎无法找到答案。 Let me also mention that I'm somewhat new to programming and have only been doing it a few months. 我还要提一下,我对编程有点新意,并且只做了几个月。

With that out of the way here is whats going on. 随之而来的是这里发生了什么。

I have a panel with a system.drawing graphics attached to it so I can render out pictures. 我有一个带有system.drawing图形的面板,所以我可以渲染图片。

With these pictures that I render to the panel I want to be able to move them around, and then interact with them with and rotate them. 通过我渲染到面板的这些图片,我希望能够移动它们,然后与它们交互并旋转它们。 Kinda like a jigsaw puzzle. 有点像一个拼图游戏。

I can get the images to render, but need a way to tell if my mouse is over the picture that was last rendered in that location. 我可以让图像渲染,但需要一种方法来判断我的鼠标是否位于该位置最后渲染的图片上方。 Since an image might render overtop of another image I want to get the top/last rendered image. 由于图像可能会渲染到另一个图像的上方,我想要获得最上面/最后一个渲染图像。

Currently i have the images in a list that get rendered and I do have a couple of ideas of my own. 目前我有一个列表中的图像被渲染,我有自己的几个想法。

  1. On a mouse click I scan all the image list last to first and find one that is currently being rendered in that spot and that would be my image. 在鼠标单击时,我最后扫描所有图像列表,然后找到当前正在该点中呈现的图像,这将是我的图像。

  2. Re render the screen last to first and as soon as a pixel changes where my mouse is that is my image. 重新渲染屏幕的第一个,一旦像素发生变化,鼠标就是我的图像。

  3. Assign each pixel a image value and when rendering the image the pixels that are on it get assigned that image and the mouse can just pull that image. 为每个像素分配一个图像值,并且在渲染图像时,其上的像素被分配给该图像,鼠标只能拉动该图像。

Any help or feedback would be much appreciated. 任何帮助或反馈将不胜感激。

Thank you. 谢谢。

The method you use will probably be largely dependent on your application. 您使用的方法可能在很大程度上取决于您的应用程序。 Without knowing much about what you're trying to do solution 3 seems the best. 在不了解您尝试解决的问题的情况下,3似乎是最好的。

With option 3 the majority of the work is being carried out as you add each image (ie assigning its value to the pixels it covers). 使用选项3,大部分工作在添加每个图像时执行(即将其值分配给它所覆盖的像素)。 The other options are are probably going to be less computationally expensive when you add the images but more expensive every mouse click. 当您添加图像时,其他选项可能在计算上不那么昂贵,但每次鼠标点击都会更昂贵。 Assuming that this suits your application (which it most probably does if its similar to a jigsaw as you stated) I'd go with something like that. 假设这适合你的应用程序(如果它类似于你所说的拼图,它很可能会这样做)我会选择类似的东西。

It also assumes that your images are rectangular shapes where values can be added based on the corners rather than an arbitrary shape in which all points in the image must be manually calculated. 它还假设您的图像是矩形,其中可以根据角添加值,而不是任意形状,其中必须手动计算图像中的所有点。 With an arbitrary shape working out which method will be quicker will be more difficult to work out. 使用任意形状来确定哪种方法更快将更难以解决。

In summary, you'd be best to decide what operation will be carried out more often (adding images or mouse clicks) and carry out the work at the other one. 总之,您最好决定更频繁地执行哪些操作(添加图像或鼠标点击)并在另一个上执行工作。

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

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