111,092
社区成员




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace 鼠标定位
{
public partial class Form1 : Form
{
List<GraphicsPath> path = new List<GraphicsPath>();
public Form1()
{
InitializeComponent();
Run100();
}
void Run100()
{
System.Random rnd = new Random();
int x, y;
for (int i = 0; i < 100; i++)
{
x = rnd.Next(this.Width);
y = rnd.Next(this.Height);
var p = new GraphicsPath();
p.AddEllipse(x, y, 5, 5);
path.Add(p);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
foreach (var p in path)
e.Graphics.DrawPath(Pens.Red, p);
}
protected override void OnMouseMove(MouseEventArgs e)
{
var p = path.Find(t=>t.IsVisible(e.X,e.Y));
if(p != null)
{
var r = p.GetBounds();
toolTip1.ToolTipTitle = "标题";
toolTip1.Show(string.Format("圆心:{0},{1}", (r.Left + r.Right) / 2, (r.Top + r.Bottom) / 2), this);
}
else toolTip1.Hide(this);
}
}
}