C# 使GTK#文件选择器仅选择文件
我正在使用GTK#C# 使GTK#文件选择器仅选择文件,c#,mono,gtk,gtk#,C#,Mono,Gtk,Gtk#,我正在使用GTK#文件选择器对话框小部件。问题是,即使小部件名为文件选择器,您也可以使用它选择文件夹,并且它还返回文件夹名称。 有什么方法可以限制它只选择文件吗?我检查了几乎所有我找不到的属性。根据文档,该行为取决于属性: 如果设置为FileChooserAction.Open或FileChooserAction.Save,则只能选择文件 如果设置为FileChooserAction.SelectFolder或FileChooserAction.CreateFolder,则只能选择文件夹 根据
文件选择器对话框
小部件。问题是,即使小部件名为文件选择器,您也可以使用它选择文件夹,并且它还返回文件夹名称。
有什么方法可以限制它只选择文件吗?我检查了几乎所有我找不到的属性。根据文档,该行为取决于属性:
- 如果设置为
或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操作:
可以通过在构造函数中定义动作属性来限制动作
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操作:
谢谢,会查回来的谢谢,会查回来的