如何获取与面板相关的鼠标坐标? [英] How can I get the mouse coordinates related to a panel?
本文介绍了如何获取与面板相关的鼠标坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图获得一个点击的坐标与鼠标在C#相关的一个面板在我的形式,但我不知道该怎么做。我是一个乞丐,我没有任何经验的事件。谢谢!
I am trying to get the coordinates of a click with the mouse in C# related to a panel in my form, but I don't know how to do that. I'm a begginer and I don't have any experience with events. Thanks!
推荐答案
您必须订阅Panel控制事件 - 点击事件。
您可以在Form的结构中编写下面的代码:
You must subscribe to event of Panel control - Click event. You can write the code below within Form's contructor:
System.Windows.Forms.Panel panel;
public Form()
{
InitializeComponent();
panel = new System.Windows.Forms.Panel();
panel.Location = new System.Drawing.Point(82, 132);
panel.Size = new System.Drawing.Size(200, 100);
panel.Click += new System.EventHandler(this.panel_Click);
this.Controls.Add(this.panel);
}
private void panel_Click(object sender, EventArgs e)
{
Point point = panel.PointToClient(Cursor.Position);
MessageBox.Show(point.ToString());
}
有关事件的更多详情,请访问此处
For more details about events go here
这篇关于如何获取与面板相关的鼠标坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文