2014-01-10 37 views
-1

我想從窗體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

那麼,您是否看到加載的圖像? – Steve

+0

是的,我現在需要的是在標籤中顯示路徑(它來自哪裏)。 – user3177361

回答

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屬性設置爲填充

+0

謝謝。這很簡單。 – user3177361

相關問題