C# 使GTK#文件选择器仅选择文件

C# 使GTK#文件选择器仅选择文件,c#,mono,gtk,gtk#,C#,Mono,Gtk,Gtk#,我正在使用GTK#文件选择器对话框小部件。问题是,即使小部件名为文件选择器,您也可以使用它选择文件夹,并且它还返回文件夹名称。 有什么方法可以限制它只选择文件吗?我检查了几乎所有我找不到的属性。根据文档,该行为取决于属性: 如果设置为FileChooserAction.Open或FileChooserAction.Save,则只能选择文件 如果设置为FileChooserAction.SelectFolder或FileChooserAction.CreateFolder,则只能选择文件夹 根据

我正在使用GTK#
文件选择器对话框
小部件。问题是,即使小部件名为文件选择器,您也可以使用它选择文件夹,并且它还返回文件夹名称。
有什么方法可以限制它只选择文件吗?我检查了几乎所有我找不到的属性。

根据文档,该行为取决于属性:

  • 如果设置为
    FileChooserAction.Open
    FileChooserAction.Save
    ,则只能选择文件
  • 如果设置为
    FileChooserAction.SelectFolder
    FileChooserAction.CreateFolder
    ,则只能选择文件夹

根据文档,该行为取决于属性:

  • 如果设置为
    FileChooserAction.Open
    FileChooserAction.Save
    ,则只能选择文件
  • 如果设置为
    FileChooserAction.SelectFolder
    FileChooserAction.CreateFolder
    ,则只能选择文件夹

您可以通过在构造函数中定义动作属性来限制动作

private void OpenOFD()
{
    Gtk.FileChooserDialog filechooser =
        new Gtk.FileChooserDialog("Choose the file to open",
            this,
            FileChooserAction.Open,
            "Cancel",ResponseType.Cancel,
            "Open",ResponseType.Accept);

    if (filechooser.Run() == (int)ResponseType.Accept) 
    {
        System.IO.FileStream file = System.IO.File.OpenRead(filechooser.Filename);
        file.Close();
    }

    filechooser.Destroy();
}
有4个FolderChoose操作:

  • CreateFolder:表示创建新文件夹的模式。选择器将允许用户名访问现有文件夹或新文件夹
  • 打开:将仅拾取现有文件
  • 保存:将拾取现有文件或键入新文件名
  • SelectFolder:选择一个ExitString文件夹

  • 可以通过在构造函数中定义动作属性来限制动作

    private void OpenOFD()
    {
        Gtk.FileChooserDialog filechooser =
            new Gtk.FileChooserDialog("Choose the file to open",
                this,
                FileChooserAction.Open,
                "Cancel",ResponseType.Cancel,
                "Open",ResponseType.Accept);
    
        if (filechooser.Run() == (int)ResponseType.Accept) 
        {
            System.IO.FileStream file = System.IO.File.OpenRead(filechooser.Filename);
            file.Close();
        }
    
        filechooser.Destroy();
    }
    
    有4个FolderChoose操作:

  • CreateFolder:表示创建新文件夹的模式。选择器将允许用户名访问现有文件夹或新文件夹
  • 打开:将仅拾取现有文件
  • 保存:将拾取现有文件或键入新文件名
  • SelectFolder:选择一个ExitString文件夹

  • 谢谢,会查回来的谢谢,会查回来的