C# 如何捕获表单的一部分
我想捕获表单的一部分并在位图变量中绘制它…C# 如何捕获表单的一部分,c#,windows,winforms,screenshot,C#,Windows,Winforms,Screenshot,我想捕获表单的一部分并在位图变量中绘制它… 当我使用drawToBitmap()函数并设置矩形(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)); 好的,我在这里创
当我使用drawToBitmap()函数并设置
矩形(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));
好的,我在这里创建了一个新表单,添加了一个按钮和一个图片框。单击按钮时,它会从窗体中剪切出一个矩形,并将其绘制到picturebox 我使用-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;
}
请显示您当前的代码。这不是个人支持热线。没有人坐在旁边只是为了帮助你。如果你发布了你的问题,人们会在浏览网站并想回答的时候回答你。每5分钟发一次垃圾评论也无济于事,事实上,很可能会把人们赶走。