我正在使用 GTK# FileChooserDialog
小部件。问题是,即使该小部件被命名为文件选择器,您也可以使用它选择文件夹,它也会返回文件夹名称。
有什么办法可以限制它只选择文件吗?我检查了几乎所有我找不到的属性。
最佳答案
你可以通过在构造函数中定义它的Action-Property来限制 Action
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 个 FolderChooserActions:
- CreateFolder:表示创建新文件夹的方式。选择器会让用户命名一个现有的或新的文件夹
- 打开:只会选择一个现有文件
- 保存:将选择现有文件或输入新文件名
- SelectFolder:选择一个现有的文件夹
关于c# - 使 GTK# 文件选择器仅选择文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612468/