我想获得鼠标点击控制坐标。比方说,运行我的应用程序用户点击Visual Studio文件菜单后。所以,我想获得文件菜单控制坐标。这是我试过的代码。我没有成功获得它。 注意:这是windform应用程序。如何在鼠标上获取控制坐标单击? C#
if (ClientRectangle.Contains(PointToClient(Control.MousePosition)))
{
// MessageBox.Show("Width:" + ClientRectangle.Width.ToString() + "--- Height: " + ClientRectangle.Height.ToString() + "---" + "X:" + ClientRectangle.X.ToString() + "--- Y: " + ClientRectangle.Y.ToString());
Point location = button1.PointToScreen(Point.Empty);
MessageBox.Show(location.X.ToString()+"---------"+location.Y.ToString()+"---------"+ location+ClientRectangle.Width.ToString()+"---------"+ClientRectangle.Height.ToString());
// Rectangle rect = new Rectangle(0, 0, 100, 100);
int with = ClientRectangle.Width;
int height = ClientRectangle.Height;
Bitmap bmp = new Bitmap((int)with, (int)height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
// g.CopyFromScreen(ClientRectangle.Left, ClientRectangle.Top, 50,50, bmp.Size, CopyPixelOperation.SourceCopy);
g.CopyFromScreen(location.X, location.Y, 0, 0, new Size(ClientRectangle.Width-30, ClientRectangle.Height-36));
bmp.Save(@"capture.jpg", ImageFormat.Jpeg)
}
任何暗示代码将不胜感激。
在Web应用程序,计算光标x和y位置,并减来自各个位置的div的偏移量x和y。我认为你可以做那样的事情。你的抵消将是控制的立场。不确定菜单,但你可以有一个想法。 – Phiter
什么类型的应用程序? WPF,WinForms,ASP.NET(MVC/WebForms)? –
*“控制鼠标点击坐标”* - 呃,什么?你怎么知道这将是一个“控制”?如果你知道点击了什么,你将如何处理它? – Sinatr