[英]How to save PictureBox and TextBox in one image?
您好想将我的所有属性(pictureBox1 + pictureBox2 + ... + Textbox2)记录在一张图像中。
private void button2_Click(object sender, EventArgs e)
{
try
{
if (pictureBox1.Image != null)
{
string nom = textBox1.Text;
string filename = string.Format(@"c:\\Users\\9408054W\\Documents\\QrCodeGenerator\\BadgeQRCode{0}.png", nom);
pictureBox1.Image.Save(filename);
button2.Text = "QRCode sauvegardé.";
button2.BackColor = Color.Green;
}
}
catch (Exception)
{
MessageBox.Show("Une erreur est survenue lors de la sauvegarde." +
"Check the file permissions.");
button2.BackColor = Color.Red;
}
}
您可以在一个panel
控件中提供所有控件。 在Button_Click
事件上,您可以获取panel
控件的高度和宽度并将其另存为图像。
Winform设计
按钮单击事件
private void btnSaveImage_Click(object sender, EventArgs e)
{
int width = panel.Size.Width;
int height = panel.Size.Height;
Bitmap bm = new Bitmap(width, height);
panel.DrawToBitmap(bm, new Rectangle(0, 0, width, height));
bm.Save(@"D:\TestDrawToBitmap.png", ImageFormat.Png);
}
图片已保存
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.