如何将控件的屏幕快照保存到剪贴板?

时间:2019-08-02 20:58:18

标签: c# winforms

如何使用winforms中的C#将特定用户控件的屏幕快照保存到剪贴板?

要清楚,以下是我想要的:

 public void SaveControlToClipboard(Control theControl){
     // Gets a bitmap of the control and saves it to the clipboard
 }

2 个答案:

答案 0 :(得分:3)

要将屏幕截图复制到整个控件的剪贴板,请使用以下功能:

    private void CopyControlToClipboard(Control theControl)
    {
        // Copy the whole control to a clicp board
        Bitmap bm = new Bitmap(theControl.Width, theControl.Height);
        theControl.DrawToBitmap(bm, new Rectangle(0, 0, theControl.Width, theControl.Height));
        Clipboard.SetImage((Image)bm);
    }

答案 1 :(得分:-1)