0

我有一个带有选项卡控件的winform,并且正在向选项卡页添加一个图片框控件。我想在标签页中将图像加载到此图片框控件。我将控件添加到标签页如下:

// initializing the picture box control
m_Canvas = new PhotoCanvas(); 
m_Canvas.BackColor = Color.White;
m_Canvas.Width = 500;
m_Canvas.Height = 400;
m_Canvas.Left = 0;
m_Canvas.Top = 0;

//adding the picture box control to tabpage
this.MainTab.TabPages[0].Controls.Add(m_Canvas);

我尝试使用以下方式加载图像OpenFileDialog

m_Canvas.Image = new Bitmap(m_OpenFileDialog.FileName);

但它没有显示加载的图像有人可以帮助我吗?

来自评论:

我正在使用一个按钮来加载图像,它的点击事件中的代码是

private void Openbutton_Click_1(object sender, EventArgs e) {
  m_OpenFileDialog.Title = "Select Image";
  if (m_OpenFileDialog.ShowDialog() == DialogResult.OK) {
    m_Canvas.Image = new Bitmap(m_OpenFileDialog.FileName);
    m_Canvas.Refresh();
  }
}
4

1 回答 1

0

尝试:

string path = m_OpenFileDialog.FileName;
m_Canvas.Image = System.Drawing.Bitmap.FromFile(path);
于 2013-03-27T10:38:22.953 回答