private void startBot_Click(object sender, EventArgs e)
{
Bitmap bmpScreenshot = Screenshot();
this.BackgroundImage = bmpScreenshot;
}
private Bitmap Screenshot()
{
// This is where we will store a snapshot of the screen
Bitmap bmpScreenshot =
new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
// Creates a graphic object so we can draw the screen in the bitmap (bmpScreenshot);
Graphics g = Graphics.FromImage(bmpScreenshot);
// Copy from screen into the bitmap we created
g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
// Return the screenshot
return bmpScreenshot;
}
我最近在尝试使用C#,正在跟随一些教程,但我不明白的是,如果我删除了Graphics g
,为什么就不能将图像作为背景,但代码中从未给变量之间分配任何关系,除了Graphics g = Graphics.FromImage(bmpScreenshot)
,然后给g
设置了一些参数,但是我们却return bmpScreenshot
,这根本没有任何意义,我期望返回的应该是g
?
CopyFromGraphics
方法的文档非常启发人心:http://msdn.microsoft.com/zh-cn/library/fw1kt6f9(v=vs.110).aspx - George Stocker