您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

打开文件对话框,然后使用WPF控件和C#选择文件

打开文件对话框,然后使用WPF控件和C#选择文件

那样的东西应该是您所需要的

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 Text@R_709_2419@ 
    if (result == true)
    {
        // Open document 
        string filename = dlg.FileName;
        text@R_709_2419@1.Text = filename;
    }
}
c# 2022/1/1 18:21:45 有459人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶