GraphicsPath相当难的问题

天地客人 天地客人 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在Winform中随机生成100个小圆,当鼠标移上去时,显示当前是哪一个圆(索引或坐标),坐等大家回复!!

原码如下:
using System;
using System.Drawing;
using System.Windows.Forms;

namespace DrawDeom
{
public partial class Form2 : Form
{
private Point[] aDraw = new Point[100];
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

public Form2()
{
InitializeComponent();
Run100();
}

private void Run100()
{
System.Random rnd = new Random();

int x, y;

for (int i = 0; i < aDraw.Length; i++)
{
x = rnd.Next(this.Width);
y = rnd.Next(this.Height);
aDraw[i].X = x;
aDraw[i].Y = y;

path.AddEllipse(x, y, 5, 5);
}
}

private void Draw(Graphics _g)
{
Pen redPen = new Pen(Color.Red, 1);
_g.DrawPath(redPen, path);
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Draw(e.Graphics);
}

protected override void OnMouseMove(MouseEventArgs e)
{
Point p = System.Windows.Forms.Control.MousePosition;
toolStripStatusLabel1.Text = string.Format("X:{0}-Y{1}", p.X, p.Y);
p = this.PointToClient(p);
if (path.IsVisible(p.X, p.Y))
{
toolStripStatusLabel1.ForeColor = Color.Red;
toolTip1.ToolTipTitle = "标题";
//显示当前圆的索引或左上角坐标
toolTip1.Show("当前图形:XX", this);
}
else
{
toolStripStatusLabel1.ForeColor = Color.Black;
toolTip1.Hide(this);
}
}
}
}
...全文

相关推荐

GDI+编程之GraphicsPath应用 !

有关判定指定控件内的鼠标是否移动到GraphicsPath路径内,并以此引发该控件的重绘事件。

后海

C#中GraphicsPath的AddString方法用法实例

本文实例讲述了C#中GraphicsPath的AddString方法用法。分享给大家供大家参考。具体如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace advanced_drawing { public partial cl

weixin_38736760

C#中GraphicsPath的Warp方法用法实例

本文实例讲述了C#中GraphicsPath的Warp方法用法。分享给大家供大家参考。具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace advanced_drawing { public partial cla

weixin_38646902

C#中GraphicsPath的Flatten方法用法实例

本文实例讲述了C#中GraphicsPath的Flatten方法。分享给大家供大家参考。具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace advanced_drawing { public partial cl

weixin_38708105

C#中GraphicsPath的Widen方法用法实例

主要介绍了C#中GraphicsPath的Widen方法用法,实例分析了Widen方法的使用技巧,需要的朋友可以参考下

weixin_38589168
评论 7
收藏 已收藏
分享
返回顶部
天地客人
C# 111,129 成员 642,538 内容