2013-07-09 37 views
0

平臺:UBUNTU
IDE:MonoDevelop的2.8.6.3
語言:C#.NET以編程方式在窗體中創建窗體並顯示位圖?

我創建了一個功能,這使得截圖並返回該截圖爲位圖。像這樣:

/*用於存儲位圖數據的變量*/
位圖bmp;

/*創建截圖。將結果返回到變量'bmp'*/
getScreenShot(bmp);

我的問題是:

如何創建一個表單/窗口(或任何有意義的),它顯示的截圖(即BMP數據)?我想以編程方式進行。

我試圖做這樣的:

public static void Main (string[] args) 
    { 

     Bitmap bmp = null; 
     Form form = new Form 
     { 
      Name = "Screenshot Displayer", 
      Size = new System.Drawing.Size(800, 800), 
          Location = new System.Drawing.Point(140, 170), 
          Visible=true 
     }; 



     /* Get screenshot */ 
     Gdk.Global.InitCheck(ref args); 
        screenCapture.getScreenShot(bmp); 

     form.BackgroundImage = bmp; 
     form.Show(); 






    } 

我想這也和它不工作。

PictureBox P = new PictureBox(); 
Bitmap bmp = null; 
Form form = new Form 
{ 
    Name = "Screenshot Displayer", 
    Size = new System.Drawing.Size(800, 800), 
    Location = new System.Drawing.Point(140, 170), 
    Visible=true 
}; 

bmp = new Bitmap("screenshot0.bmp"); 
P.Image = bmp; 
form.Controls.Add (P); 
form.Show(); 

回答

1

添加一個圖片是碼頭填寫form.Then顯示截圖是這樣的:

pictureBox1.Image=bmp; 
+0

你能告訴我一個例子?我嘗試了你的建議,但它不起作用。 – user1884325

+0

PictureBox P = new PictureBox(); 位圖bmp = null; 表格形式=新形態 { 名稱= 「截圖顯示儀」, 大小=新System.Drawing.Size(800,800), 位置=新System.Drawing.Point(140,170), 可見=真 }; bmp = new Bitmap(@「example.bmp」); P.Image = bmp; P.Dock = DockStyle.Fill; form.Controls.Add(P); form.Show(); – user2492798

+0

如果你不想在窗體上有一個圖片框,並且想要在窗體上繪製它,就像在表單 –

0

「如何創建一個表單/窗口(或任何有意義的),這顯示截圖(即bmp數據)?我想以編程方式進行。「

嘗試:
(編譯下面應該顯示您的Bitmap,研究代碼,並要求任何東西):

//# Declare a PictureBox (as bitmap container) 
PictureBox pbx; 

//# Setup the PictureBox 
pbx = new PictureBox 
{ 
    Name = "pictureBox99", 
    Size = new Size(640, 480), 
    Location = new Point(0, 0), 
    Visible=true 
}; 

//# Link PictureBox to code for reference 
this.Controls.Add(pbx); 

// Add your Bitmap as source 
pbx.Image = your_Bitmap_object; 
相關問題