简体   繁体   English

如何在C#中获得Click控件的图像?

[英]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.

相关问题 如何获取C#中动态生成的控件的值? - How do I get the value of a dynamically generated control in C#? 如何单击按钮并通过C#获取excel文件? - How do I click button and get excel file by C#? c#如何在html通用控件中调用图像按钮的单击事件? - c# how can i call click event of image button in html generic control? 如何通过单击一个按钮选择C#复选框控件中的前30个项目 - How do I select the top 30 items in a C# checkbox control with a single button click 如何从C#单击嵌入式Web控件上的按钮? - How do I click a button on an embedded web control from C#? 如何在C#中获取位图图像的背景色? - How do I get the background color of Bitmap Image in c#? 如何在C#中从ImageView获取图像大小? - How do I get the image size from a ImageView in c#? 在C#WinForms浏览器控件中单击图像 - Image click in C# WinForms Browser Control 如何使用 selenium C# 右键单击​​图像并复制图像地址? - How do I right-click on an image and Copy image address using selenium C#? 将UniformToFill与图像一起使用时,如何在C#或XAML中控制剪裁 - How do I control clipping in C# or XAML when using UniformToFill with an image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM