Open file dialog and select a file using WPF controls and C#

后端 未结 2 712
盖世英雄少女心
盖世英雄少女心 2020-11-27 11:13

I have a TextBox named textbox1 and a Button named button1. When I click on button1 I want to browse my file

2条回答
  •  野性不改
    2020-11-27 11:23

    var ofd = new Microsoft.Win32.OpenFileDialog() {Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"}; 
    var result = ofd.ShowDialog();
    if (result == false) return;
    textBox1.Text = ofd.FileName;
    

提交回复
热议问题