Load a bitmap image into Windows Forms using open file dialog

后端 未结 8 757
梦毁少年i
梦毁少年i 2020-12-10 02:21

I need to open the bitmap image in the window form using open file dialog (I will load it from drive). The image should fit in the picture box.

Here is the code I t

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 02:51

    Works Fine. Try this,

    private void addImageButton_Click(object sender, EventArgs e)
    {
        OpenFileDialog of = new OpenFileDialog();
        //For any other formats
        of.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG"; 
        if (of.ShowDialog() == DialogResult.OK)
        {
            pictureBox1.ImageLocation = of.FileName;
    
        }
    }
    

提交回复
热议问题