[英]How do I get Image of Control on Click in C#?
I want to get exact that Control Image on which I click. 我想确切获得单击它的那个控制图像。
Like If I clicked on Save as option.I should get the save as control Image. 就像如果单击“另存为”选项。我应该将另存为控件图像。
Here is Image Example Which I want to achieve. 这是我要实现的图像示例。 First I clicked on File Menu then Save as.
首先,我单击文件菜单,然后单击另存为。
I want to achieve this 我想实现这一目标
Currently. 目前。 I am getting the image on clicked base of coordinates of Click.
我在Click坐标的单击基础上获取图像。 Like this.I am getting Image on Click base of Click Coordinates.This is not what I want to do.
像这样。我在点击坐标的点击基础上获得图像。这不是我想要的。
Another Example. 另一个例子。 I clicked on Stack over flow questions control.
我单击了Stack over Flow问题控件。 I should get this result.
我应该得到这个结果。
My code. 我的代码。
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)
From what i understood from your question, you want to show the image of the menu option on mouse pointer when mouse is pointed/clicked on that particular menu item. 根据我对您的问题的理解,当鼠标指向/单击特定菜单项时,您想在鼠标指针上显示菜单选项的图像。 If that's so you can do this by changing Cursor:
如果是这样,您可以通过更改Cursor来做到这一点:
System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(new Uri("/Images/handClosed.cur", UriKind.RelativeOrAbsolute));
Cursor customCursor = new Cursor(sri.Stream);
Mouse.OverrideCursor = customCursor;
Here, "/Images/handClosed.cur" is a locally stored image in the project. 此处,“ / Images / handClosed.cur”是项目中本地存储的图像。 You can store the images for all the menu item and show them like this based on the menu item.
您可以存储所有菜单项的图像,并根据菜单项像这样显示它们。
Edit: This is a WPF Example 编辑:这是一个WPF示例
Check this Simple Magnifier app. 检查此简单放大镜应用程序。 Reference the source and to get the desired effect on mouse click.
参考源,并在单击鼠标时获得所需的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.