Windows窗体PictureBox – 如何在窗体的某个区域中显示图像

我正在使用以下代码使用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); } } } 

问题是我的图像显示在我的表单的左上角,当我为此目的离开了几乎四分之一的右下角时。 我怎么能在那里展示它?

就像我在评论中所说,这是如何: 如何:在Windows窗体上定位控件

 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 

您可以在将PictureBox添加到Parent之前设置它的location属性。