0

How to save a screenshot of a specific user control to the clipboard with winforms in C#?

To be clear the following is what I desire:

 public void SaveControlToClipboard(Control theControl){
     // Gets a bitmap of the control and saves it to the clipboard
 }
grolschie
  • 2,163
  • 2
  • 12
  • 29
Cabbage Champion
  • 1,193
  • 1
  • 6
  • 21

2 Answers2

4

To copy a screen shot to the clipboard of an entire control, use the following function:

    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);
    }
Cabbage Champion
  • 1,193
  • 1
  • 6
  • 21
-1

Using takeComponentScreenShot from https://stackoverflow.com/a/29315808/6468720

And than use Clipboard.SetImage(Image), MSDN link: https://learn.microsoft.com/ru-ru/dotnet/api/system.windows.forms.clipboard.setimage?view=netframework-4.8