windows表格中如何判断光标位置是否在图表控件之外?
How to check whether the cursor position is outside of chart control in the windows form?
我在 MS chart
中显示 tooltip
。当从图表控件移动到其他控件或表单自由 space 时,tooltip
不会被隐藏。
如何在windows表格中判断光标位置是否在图表控件之外?
我试过下面的代码,它对我不起作用。
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (!chart.ClientRectangle.Contains(chart.PointToClient(new Point(e.X,e.Y))))
{
if (ToolTip != null)
ToolTip.Hide(chart);
}
}
我跟踪并检查,如果我从图表控件移动到自由 space 表单,事件就会触发,只有当从图表移动到其他控件时,才不会调用 Form1_MouseMove
。
如何解决我的问题?
尝试在目标控件(你的图表,我的按钮)上处理 MouseEnter
和 MouseLeave
事件。
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class Form1 : Form
{
private const string mouseIsOver = "Mouse is over";
private const string mouseIsOutside = "Mouse is outside";
public Form1()
{
InitializeComponent();
var button = new Button { Text = mouseIsOutside, AutoSize = true, Location = new Point(10, 10) };
button.MouseEnter += (sender, e) => button.Text = mouseIsOver;
button.MouseLeave += (sender, e) => button.Text = mouseIsOutside;
this.Controls.Add(button);
}
}
}
我在 MS chart
中显示 tooltip
。当从图表控件移动到其他控件或表单自由 space 时,tooltip
不会被隐藏。
如何在windows表格中判断光标位置是否在图表控件之外?
我试过下面的代码,它对我不起作用。
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (!chart.ClientRectangle.Contains(chart.PointToClient(new Point(e.X,e.Y))))
{
if (ToolTip != null)
ToolTip.Hide(chart);
}
}
我跟踪并检查,如果我从图表控件移动到自由 space 表单,事件就会触发,只有当从图表移动到其他控件时,才不会调用 Form1_MouseMove
。
如何解决我的问题?
尝试在目标控件(你的图表,我的按钮)上处理 MouseEnter
和 MouseLeave
事件。
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp
{
public partial class Form1 : Form
{
private const string mouseIsOver = "Mouse is over";
private const string mouseIsOutside = "Mouse is outside";
public Form1()
{
InitializeComponent();
var button = new Button { Text = mouseIsOutside, AutoSize = true, Location = new Point(10, 10) };
button.MouseEnter += (sender, e) => button.Text = mouseIsOver;
button.MouseLeave += (sender, e) => button.Text = mouseIsOutside;
this.Controls.Add(button);
}
}
}