2012-05-17 35 views
0

我想捕捉我的表格的一部分,並在位圖變量中繪製它...
當我使用drawToBitmap()函數和設置rectangle(12,40,...),該函數只是從0,0點捕獲表格。
那麼我該怎麼做才能解決這個問題?
坦克的幫助如何捕捉表格的一部分

Bitmap bmp = new Bitmap(((int)maxWidth)+2, ((int)maxHeight)+2); 
this.DrawToBitmap(bmp,new Rectangle(0,40,((int)maxWidth)+2, ((int)maxHeight)+2)); 
+0

請顯示您的當前代碼。 – Yuck

+0

任何幫助.... !!!!! –

+4

這不是個人支持熱線。沒有人只是爲了幫助你而坐着。你發佈了你的問題,人們會在他們瀏覽網站並回復時回答。每5分鐘發送一次垃圾郵件並不會有幫助,事實上,這可能會將人們趕走。 –

回答

2

好了,所以我在這裏所做的創建一個新的形式,並增加了一個按鈕和一個圖片框。當您單擊該按鈕時,它會從窗體中剪切出一個矩形並將其繪製到圖片框。

我用-100,0將圖像移動到左邊100像素。

private void button1_Click(object sender, EventArgs e) 
    { 
     //The image we will be drawing on then passing to picturebox 
     Bitmap bmp=new Bitmap(pictureBox1.Width,pictureBox1.Height); 

     using (Graphics g=Graphics.FromImage(bmp)) 
     { 
      using (Bitmap b = new Bitmap(this.Width, this.Height)) 
      { 
       //captures the Form screenschot, and saves it into Bitmap b 
       this.DrawToBitmap(b, new Rectangle(0, 0, this.Width, this.Height)); 

       //this draws the image from Bitmap b starting at the specified location to Bitmap bmp 
       g.DrawImageUnscaled(b, -100, 0); 
      } 
     } 
     //this assigns pictureBox1 the bmp Bitmap. 
     pictureBox1.Image = bmp; 
    }