File Dialog (native)
Introduction
Code Example
Label label = new Label();
label.Y = 100;
label.AddToRoot();
Button button = new Button();
button.AddToRoot();
button.Click += (_,_) =>
{
using var selectFileDialog = new NativeFileDialog()
.SelectFile()
.AllowMultiple(); // Optionally allow multiple selections
DialogResult result = selectFileDialog.Open(out string[]? output,
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
label.Text = result switch
{
DialogResult.Okay => $"Selected: {string.Join(", ", output ?? Array.Empty<string>())}",
DialogResult.Cancel => "Selection canceled.",
DialogResult.Error => "An error occurred while selecting a file.",
_ => $"Unknown result {result}"
};
};Last updated
Was this helpful?

