C# Windows窗体PictureBox-如何在窗体的特定区域显示图像
我正在使用以下代码使用C# Windows窗体PictureBox-如何在窗体的特定区域显示图像,c#,winforms,visual-studio-2010,C#,Winforms,Visual Studio 2010,我正在使用以下代码使用fileDialog在我的一个窗体中打开和显示图像: private void btnExplorer_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFile
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);
}
}
}
问题是,我的图像显示在表格的左上角,而我的右下角几乎有四分之一是为了这个目的。如何在那里显示它?您可以在将PictureBox添加到父对象之前设置它的location属性。正如我在评论中所说,下面是如何操作的: 或事后更改:
PictureBox1.Top += 50; //increase distance from top with 50
将图片框移到窗体的右下角?以编程方式设置控件的位置:确定。。。这是合理的,但我怎么才能做到呢?
PictureBox1.Top += 50; //increase distance from top with 50