我在Windows窗体上而不是在Picturebox上绘制图形。我想将Windows窗体的视图保存到桌面上的特殊文件夹中。我不知道是否可以制作出更好的屏幕截图,或者我应该尝试将其另存为图像(位图)在我的文件夹中。 通常,我尝试了两种选择,但它不起作用:( 我把我的尝试之一放在这里...
public void Form1_Paint(object sender, PaintEventArgs e)
{
int x1, y1, x2, y2;
Random losowa1 = new Random();
x1 = losowa1.Next(0, 200);
y1 = losowa1.Next(120, 300);
x2 = losowa1.Next(300, 480);
y2 = losowa1.Next(120,300);
e.Graphics.FillRectangle(Brushes.Black, x1, y1, 100, 100);
e.Graphics.FillEllipse(Brushes.Black, x2, y2, 100, 100);
Bitmap bitmap = new Bitmap(this.Width, this.Height);
DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save("@C:\\Desktop", ImageFormat.Jpeg);
// MessageBox.Show("saved");
System.Threading.Thread.Sleep(1000);
this.Close();
}
和
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 3; i++)
{
Form1 OknoStart = new Form1();
OknoStart.ShowDialog();
}
答案 0 :(得分:1)
尝试
int i;
public Form1(int i)
{
InitializeComponent();
this.i = i;
}
private void Form1_Load(object sender, EventArgs e)
{
using (Bitmap bmp = new Bitmap(this.Width, this.Height))
{
this.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(@"C:\Users\User\Desktop\sample" + i+".png", ImageFormat.Png);
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
int x1, y1, x2, y2;
Random losowa1 = new Random();
x1 = losowa1.Next(0, 200);
Random losowa2 = new Random();
y1 = losowa2.Next(0, 480);
Random losowa3 = new Random();
x2 = losowa1.Next(300, 500);
Random losowa4 = new Random();
y2 = losowa2.Next(0, 480);
e.Graphics.FillRectangle(Brushes.Black, x1, y1, 100, 100);
e.Graphics.FillEllipse(Brushes.Black, x2, y2, 100, 100);
System.Threading.Thread.Sleep(2000);
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i=0;i<3;i++) {
Form1 form1 = new Form1(i);
form1.ShowDialog();
}
}