C#在应用程序中获取.net控件的ScreenShot并附加到Outlook Email

bri*_*668 7 .net c# controls screenshot winforms

有没有人知道如何使用C#截取屏幕截图并限制它来拍摄特定容器/应用程序的一部分.我不想要应用程序的整个屏幕或整个窗口.

简单地调用我的面板:panel1用户将单击"按钮"并获取panel1的屏幕截图并附加到电子邮件.

我想仅拍摄该部分的屏幕截图,然后在本地保存到C:\ Drive和/或附加或嵌入到outlook电子邮件中.

我在互联网上阅读了其他各种各样的东西,但大多数都不得不处理创建复杂的变化,拍摄我不想要的网页浏览器控件的屏幕截图.

key*_*rdP 6

如果您只想要Panel's截图,可以使用内置的DrawToBitmap方法.

Bitmap bmp = new Bitmap(myPanel.Width, myPanel.Height);
myPanel.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
bmp.Save(@"C:\MyPanelImage.bmp");
Run Code Online (Sandbox Code Playgroud)

请注意,某些控件可能无法使用此功能,例如WebBrowserRichTextBox控件,但它应该适用于大多数其他控件(文本框,标签等..)


Moo*_*ght 5

我用这样的东西做这个

public static void TakeCroppedScreenShot(
    string fileName, int x, int y, int width, int height, ImageFormat format)
{
    Rectangle r = new Rectangle(x, y, width, height);
    Bitmap bmp = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
    Graphics g = Graphics.FromImage(bmp);
    g.CopyFromScreen(r.Left, r.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
    bmp.Save(fileName, format);
}
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助