Noo*_*r69 177 c# wpf textbox openfiledialog
我有一个TextBox
名字textbox1
和一个Button
名字button1
.当我点击button1
我想浏览我的文件只搜索图像文件(类型jpg,png,bmp ...).当我选择一个图像文件并在文件对话框中单击"确定"时,我希望文件目录的写入方式textbox1.text
如下:
textbox1.Text = "C:\myfolder\myimage.jpg"
Run Code Online (Sandbox Code Playgroud)
Kla*_*s78 412
这样的事情应该是你需要的
private void button1_Click(object sender, RoutedEventArgs e)
{
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".png";
dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
string filename = dlg.FileName;
textBox1.Text = filename;
}
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ave 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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
237785 次 |
最近记录: |