我想将表单1中的图像加载到另一个表单中,并在第二种表单的标签中显示图像路径。
到目前为止,这是我的代码:
private void llblOpenSavedImages_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
if (!string.IsNullOrEmpty(dlg.FileName))
{
Open_Saved_Design_Form frm = new Open_Saved_Design_Form(dlg.FileName);
frm.Show();
}
}
}
这是第二种形式:
public Open_Saved_Design_Form(string imagePath)
{
InitializeComponent();
_imagePath = imagePath;
}
private void Open_Saved_Design_Form_Load(object sender, EventArgs e)
{
pbxArt.ImageLocation = _imagePath;
}
答案 0 :(得分:0)
假设您的第二个表单中有一个名为Label1的标签,您只需添加
即可public Open_Saved_Design_Form(string imagePath)
{
InitializeComponent();
_imagePath = imagePath;
}
private void Open_Saved_Design_Form_Load(object sender, EventArgs e)
{
pbxArt.ImageLocation = _imagePath;
Label1.Text = _imagePath;
}
当然,您需要确保标签是可见的,而不是由PictureBox覆盖 例如,您可以将Label1的Dock属性设置为Bottom,然后将PictureBox的Dock属性设置为Fill