Windows窗体PictureBox的 - 如何在表格的某个区域显示图像 [英] Windows Forms PictureBox - how to display the image in a certain area of the form

查看:153
本文介绍了Windows窗体PictureBox的 - 如何在表格的某个区域显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的代码中使用的FileDialog 我的形式之一打开并显示图像:

I'm using the following code to open and display image in one of my forms using fileDialog :

private void btnExplorer_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:\\";
            openFileDialog1.Filter = "All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    PictureBox PictureBox1 = new PictureBox();
                    PictureBox1.Image = new Bitmap(openFileDialog1.FileName);
                    // Add the new control to its parent's controls collection
                    this.Controls.Add(PictureBox1);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error loading image" + ex.Message);
                }
            }
        }

的问题是,我的形象显示在我的表格左上角,当我离开我的下右侧近四分之一用于这一目的。我怎样才能显示它有

The problem is that my image is shown at the top left corner of my form, when I have left almost quarter of my down-right side for this purpose. How can I show it there?

推荐答案

就像我在我的评论说,这里是如何?的How到:Windows窗体上 位置控制。

Like I said in my comment, here's how: How to: Position Controls on Windows Forms.

PictureBox PictureBox1 = new PictureBox();
PictureBox1.Image = new Bitmap(openFileDialog1.FileName);
PictureBox1.Location = new Point(20, 100); //20 from left and 100 from top
this.Controls.Add(PictureBox1);

或之后进行更改:

PictureBox1.Top += 50; //increase distance from top with 50

这篇关于Windows窗体PictureBox的 - 如何在表格的某个区域显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆