我必须实现一个解决方案,因为我不太了解这种语言(C#),所以我不太确定如何进行。
让我来解释一下:我们的目标是让用户可以从一个项目中选择一个区域(它有一个圆形)。因此,我们的想法是在区域上放置一个带有数字的图像(这样最后它看起来就像一个时钟),并从用户点击的数字中获得区域。
所以我的问题是:可以在图片中创建可点击的区域吗?(或者,如果您对此功能有其他解决方案,我持开放态度)
提前感谢!
编辑>>这是一个WinForm应用程序,不是一个网站。
发布于 2012-04-30 21:02:46
感谢你们所有人的回答,其中有有趣的东西。
不幸的是,由于我必须非常快速地开发它,所以我只创建了一个映像,在该映像上我将捕获onclick事件,然后捕获用户使用Cursor.Position单击的区域,如下所示:
int X = pictureBox.PointToClient(Cursor.Position).X;
int Y = pictureBox.PointToClient(Cursor.Position).Y;也许不是“干净”的方式,但它是有效的!不管怎样,谢谢你!
发布于 2012-04-19 02:08:05
为什么不直接实现这样的东西呢?
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
public class Zone
{
public Region Region { get; private set; }
public Action<MouseEventArgs> Click { get; private set; }
public Zone(Region zoneRegion, Action<MouseEventArgs> click)
{
this.Region = zoneRegion;
this.Click = click;
}
}
public class PictureBoxWithClickableZones : PictureBox
{
private readonly List<Zone> zones = new List<Zone>();
public void AddZone(Zone zone)
{
if (zone == null)
throw new ArgumentNullException("zone");
this.zones.Add(zone);
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
foreach (var zone in this.zones.Where(zone => zone.Region.IsVisible(e.Location)))
zone.Click(e);
}
}如果您有足够的时间,甚至可以在Visual Studio的WinForms设计器中制作适当的组件并使用。
发布于 2012-04-17 23:20:08
尽管它不再那么流行了,但you can use the tag可以做到这一点。
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun" />
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury" />
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus" />
</map> 编辑:
由于这需要一个WinForms解决方案,因此本文可能会对您有所帮助。
C# Windows Forms ImageMap Control
https://stackoverflow.com/questions/10194017
复制相似问题