A simple example of a screenshot of the c control
- 2020-05-19 05:41:23
- OfStack
First select the path to save the image:
saveFileDialog1.Title = " save ";
saveFileDialog1.Filter = "*.png|*.png";
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
timer1.Enabled = true;
}
Next, save the control picture (to wait for the savedialoge control to close completely, use timer to delay) :
timer1.Enabled = false;
Bitmap bit = new Bitmap(this.Width, this.Height);// instantiation 1 With the form 1 The sample of bitmap
Graphics g = Graphics.FromImage(bit);
g.CompositingQuality = CompositingQuality.HighQuality;// The mass is set to the highest
//g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));// Save the entire form as a picture
g.CopyFromScreen(chartType.PointToScreen(Point.Empty), Point.Empty, chartType.Size);// Save only one control
bit.Save(saveFileDialog1.FileName);// The default save format is PNG , save into jpg The format quality is not very good
if (File.Exists(saveFileDialog1.FileName.ToString()))
{
MessageBox.Show(" Screenshot successful! ");
return;
}