【问题标题】:Displaying image on a Panel在面板上显示图像
【发布时间】:2011-05-24 04:03:40
【问题描述】:

这是我的代码的 sn-p....

 public void btn_browse_Click_Click(object sender, EventArgs e)
    {

        try
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                scan.Enabled = true;
                pic = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
                pic2 = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);                                   

                pic = new Bitmap(open.FileName);
                pic2 = new Bitmap(open.FileName);

                pictureBox1.Image = pic;
                pictureBox2.Image = pic2;
                pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                textBox1.Text = open.FileName;
                pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;



            } // end of if opendialog


        } // end of try

        catch (Exception)
        {
            throw new ApplicationException("Failed loading image");
        }


    }

问题是:我能否在 Panel 而不是 PictureBox 上显示我浏览的图像?

【问题讨论】:

    标签: c# .net panel image


    【解决方案1】:

    您可以将面板的BackGroundImage设置为图像。
    panel.BackgroundImage = Image.FromFile(open.FileName);
    应该做的伎俩。

    【讨论】:

      【解决方案2】:

      基本上 PictureBox 用于显示图像,而 Panel 用于绘图(曲线、直线、矩形……)

      所以我建议最好使用pictureBox,但如果你想在面板中显示图像。

      1. 你可以画on paint事件
        OR
      2. 使用BackgroundImage 属性。

      【讨论】:

        【解决方案3】:

        是的。 Panel class 有一个名为 BackImageUrl 的成员。只需指定要用作背景的图片的 URL。

        【讨论】:

          【解决方案4】:

          对于winforms,您可以使用面板的BackgroundImageBackgroundImageLayout 属性。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-10-25
            • 2019-06-03
            • 1970-01-01
            • 2017-11-20
            • 2017-03-13
            • 1970-01-01
            相关资源
            最近更新 更多