可点击图片地图C# [英] Clickable Image Map c#

查看:275
本文介绍了可点击图片地图C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个C#库存应用程序。然而,我希望这是一个地图,用户可点击几个方面,并与该特定区域的资源进行交互。

I'm making a C# inventory application. However, I want there to be a map where the user can click several areas and interact with the inventory on that certain area.

目前我Photoshop处理地图,并使其形式的背景。我打算把pictureboxes在不同的领域和code手动鼠标,单击和鼠标按下事件给该按钮的外观。

Currently I photoshopped the map and made it the background of the form. I'm planning on putting pictureboxes over the different areas and code manually the mouse over, click, and mouse down events to give the button appearance.

不管怎样,我的问题是,这是个好主意吗?如果我只是加载地图到一个PictureBox,摆脱buttonish视觉效果和追踪点击的坐标?

Anyway, my question is, is this a good idea? Should I just load the map into a picturebox, get rid of the buttonish visual effects and track the coordinates of the click?

推荐答案

虽然我不认为这是一个坏主意,一种选择是使用的矩形并有由一系列的 Rectangle.Contains(点)如果用鼠标单击该点被包含在任何可点击区域的找出来。

While I don't think this is a bad idea, one alternative would be to use Rectangles and have an onclick function consisting of a series of Rectangle.Contains(Point) to find out if the point clicked by the mouse is contained in any of the clickable areas.

例如

Rectangle R1 = new Rectangle(/*Passed Variables*/);
Rectangle R2 = new Rectangle(/*Passed Variables*/);
//...
OnClick(object sender, MouseEventArgs e)
 {
 If (R1.Contains(e.Location))
  {
   //Stuff
  }
 else
 {
  If (R2.Contains(e.Location))
   {
    //Stuff
   }
 }
}

如果你有矩形的对象的较大的列表,但是,你总是可以,如果点击位置是任何矩形内使用矩形的for循环的阵列和一个用于检查的更有效的方法。

If you have a larger list of Rectangle objects, though, you could always use an array of Rectangles and a for loop for a more efficient way of checking if the clicked location is inside any Rectangle.

这篇关于可点击图片地图C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆