private async void FileSave_Click(object sender, MouseClickEventArgs e) { if (string.IsNullOrEmpty(this._CurrentFileName)) { SaveFileDialog sfd = new SaveFileDialog { Title = "Save file as...", Filter = "All Files(*.*)\0*.*\0Text(*.txt)\0*.txt\0", DefaultFilterIndex = 2 }; if (sfd.Show(this)) { this._CurrentFileName = sfd.File; string text = this._TextBox.Text; await File.WriteAllTextAsync(this._CurrentFileName, text); this.Text = "Little Edit:" + this._CurrentFileName; } } else { string text = this._TextBox.Text; File.WriteAllText(this._CurrentFileName, text); this.Text = "Little Edit:" + this._CurrentFileName; } }
public FileResultModel ShowSaveFileDialog(SaveFileDialogConfigModel config) { var dialog = new SaveFileDialog { Title = config.Title, InitialDirectory = config.InitialDirectory, FileName = config.FileName, OverwritePrompt = config.OverwritePrompt, }; if (config.FileFilters != null) { foreach (var filter in config.FileFilters) { dialog.FileFilters.Add(filter.ToFilter()); } } var result = Application.Invoke(() => dialog.Show(parent)); return(new FileResultModel { DialogResult = result, File = dialog.FileName, Files = new string[] { dialog.FileName }, }); }
protected override void InitializeComponent() { Margins = true; Child = hPanel; hPanel.Children.Add(vPanel); vPanel.Children.Add(datePicker); vPanel.Children.Add(timePicker); vPanel.Children.Add(dateTimePicker); vPanel.Children.Add(fontPicker); vPanel.Children.Add(colorPicker); hPanel.Children.Add(hSeparator); hPanel.Children.Add(vPanel2); vPanel2.Children.Add(grid); button.Click += (sender, args) => { OpenFileDialog dialog = new OpenFileDialog(); if (!dialog.Show()) { textBox.Text = "(cancelled)"; return; } ; textBox.Text = dialog.Path; }; button2.Click += (sender, args) => { SaveFileDialog dialog = new SaveFileDialog(); if (!dialog.Show()) { textBox2.Text = "(cancelled)"; return; } ; textBox2.Text = dialog.Path; }; button3.Click += (sender, args) => { MessageBox.Show("This is a normal message box.", "More detailed information can be shown here."); }; button4.Click += (sender, args) => { MessageBox.Show("This message box describes an error.", "More detailed information can be shown here.", true); }; grid.Children.Add(button, 0, 0, 1, 1, 0, 0, Alignment.Fill); grid.Children.Add(textBox, 1, 0, 1, 1, 1, 0, Alignment.Fill); grid.Children.Add(button2, 0, 1, 1, 1, 0, 0, Alignment.Fill); grid.Children.Add(textBox2, 1, 1, 1, 1, 1, 0, Alignment.Fill); grid.Children.Add(grid2, 0, 2, 2, 1, 0, 0, Alignment.TopCenter); grid2.Children.Add(button3, 0, 0, 1, 1, 0, 0, Alignment.Fill); grid2.Children.Add(button4, 1, 0, 1, 1, 0, 0, Alignment.Fill); }
public bool AskSaveName(ref string filePath, string title) { var dialog = new SaveFileDialog(); dialog.Title = title; dialog.Filters.Add(_mgcbFileFilter); dialog.Filters.Add(_allFileFilter); dialog.CurrentFilter = _mgcbFileFilter; if (dialog.Show(this) == DialogResult.Ok) { filePath = dialog.FileName; if (dialog.CurrentFilter == _mgcbFileFilter && !filePath.EndsWith(".mgcb")) filePath += ".mgcb"; return true; } return false; }
private void InitializeComponent() { _hBox = new HorizontalBox() { AllowPadding = true }; this.Child = _hBox; _vBox = new VerticalBox() { AllowPadding = true }; _hBox.Children.Add(_vBox); _vBox.Children.Add(new DatePicker()); _vBox.Children.Add(new TimePicker()); _vBox.Children.Add(new DateTimePicker()); _vBox.Children.Add(new FontPicker()); _vBox.Children.Add(new ColorPicker()); _hBox.Children.Add(new Separator(Orientation.Vertical)); _vBox = new VerticalBox() { AllowPadding = true }; _hBox.Children.Add(_vBox); _grid = new Grid() { AllowPadding = true }; _vBox.Children.Add(_grid); _button = new Button("Open File"); _entry = new Entry() { IsReadOnly = true }; _button.Click += (sender, args) => { var dialog = new OpenFileDialog(); if (!dialog.Show()) { _entry.Text = "(cancelled)"; return; } ; _entry.Text = dialog.Path; }; _grid.Children.Add(_button, 0, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _grid.Children.Add(_entry, 1, 0, 1, 1, 1, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _button = new Button("Save File"); _entry2 = new Entry() { IsReadOnly = true }; _button.Click += (sender, args) => { var dialog = new SaveFileDialog(); if (!dialog.Show()) { _entry2.Text = "(cancelled)"; return; } ; _entry2.Text = dialog.Path; }; _grid.Children.Add(_button, 0, 1, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _grid.Children.Add(_entry2, 1, 1, 1, 1, 1, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _msgGrid = new Grid() { AllowPadding = true }; _grid.Children.Add(_msgGrid, 0, 2, 2, 1, 0, HorizontalAlignment.Center, 0, VerticalAlignment.Top); _button = new Button("Message Box"); _button.Click += (sender, args) => { MessageBox.Show("This is a normal message box.", "More detailed information can be shown here."); }; _msgGrid.Children.Add(_button, 0, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _button = new Button("Error Box"); _button.Click += (sender, args) => { MessageBox.Show("This message box describes an error.", "More detailed information can be shown here.", MessageBoxTypes.Error); }; _msgGrid.Children.Add(_button, 1, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); }