鼠标悬停在面板上时显示值。
问题描述:
我在面板中绘制了一条路径(使用选择区域的坐标)。在此我想在面板路径上悬停时显示值。我该怎么做?请帮帮我!
我的尝试:
I drawn a path(using coordinates of selecting area) in the panel.In this I want to display the values while hovering on the panel path.How will I do this? Please Help Me !
What I have tried:
points1.Add(new Point(Convert.ToInt16(x), Convert.ToInt16(y)));
Pen p = new Pen(Color.Blue, 2);
Graphics gr = Graphics.FromImage(panelname.BackgroundImage);
gr.SmoothingMode = SmoothingMode.AntiAlias;
AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5);
p.CustomEndCap = bigArrow;
g.DrawLine(p, points1[i1], points1[i1 + 1]);
这仅适用于面板中的路径显示。当鼠标悬停在路径上时,我不知道如何在路径上显示值。指导我!!
This is only for path display in panel.I don't know how to display value over the path while mouse hover the path.Guide me !!
答
这方面的一个例子可能是:
An example for this could be :
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class myPanel : Panel
{
public List<Point> ClickPoints {
get { return myClickPoints; }
set { myClickPoints = value; }
}
private List<Point> myClickPoints = new List<Point>();
public void ClearList()
{
myClickPoints.Clear();
}
protected override void OnMouseClick(MouseEventArgs e)
{
myClickPoints.Add(new Point(e.Location.X, e.Location.Y));
base.OnMouseClick(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawString(myClickPoints.Count.ToString, Font, Brushes.Black, new Point(0, 10));
base.OnPaint(e);
}
}