我有一个winform,我有tab控件,我正在向标签页添加一个图片框控件。我想在标签页中将图像加载到此图片框控件。我将控件添加到标签页如下:
// 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();
}
}
答案 0 :(得分:0)
尝试:
string path = m_OpenFileDialog.FileName;
m_Canvas.Image = System.Drawing.Bitmap.FromFile(path);