2012-03-28 93 views
-1

我有一個用Visual Studio(C#)編寫的有趣應用程序,我想知道 - 我所做的是我在窗體上以某種方式繪製面板 - 如果可以渲染窗體而不用截圖?Visual C# - 從窗體渲染圖像?

感謝

回答

3

如果「採取截圖」你的意思是「送PrtSc鍵」,然後有一個更好的辦法,用System.Drawing.Graphics.CopyFromScreen

using(Bitmap b = new Bitmap(this.ClientSize.Width, this.ClientSize.Height)) { 
    using(Graphics g = Graphics.FromImage(b)) { 
     g.CopyFromScreen(this.PointToClient(Point.Empty), Point.Empty, this.ClientSize); 
    } 

    // Your form is now rendered into b. 
} 

如果要包括邊界,只需使用Size代替ClientSizethis.Location而不是this.PointToClient(Point.Empty)

或者,你可以使用this.DrawToBitmap

using(Bitmap b = new Bitmap(this.Width, this.Height)) { 
    this.DrawToBitmap(b, new Rectangle(0, 0, this.Width, this.Height)); 

    // Your form is now rendered into b. 
} 

這會工作,即使你的形式不具有焦點。但是,如果Aero處於活動狀態,它將繪製邊框並以Windows Basic樣式繪製。

-1

不,這是不可能捕捉到視覺的形式作爲比是通過某種screenshotting庫(如果這就是你在問什麼)的提供的其他圖像。