简体   繁体   English

如何在一个图像中保存PictureBox和TextBox?

[英]How to save PictureBox and TextBox in one image?

Hi would like to record all my properties (pictureBox1 + pictureBox2 + ...+Textbox2) 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;
  }
}

要保存的东西

图片最终

You can give all the control in one panel control. 您可以在一个panel控件中提供所有控件。 And on Button_Click event,you can get the height and width of the panel control and save it as image. Button_Click事件上,您可以获取panel控件的高度和宽度并将其另存为图像。

Winform Design Winform设计

在此处输入图片说明

Button Click Event 按钮单击事件

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);
}

Image Saved 图片已保存

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM