private void OpenFile(object sender, RoutedEventArgs e) //菜单-文件-打开 { if (IsEdited == true) { SavePopWindow savePopWindow = new SavePopWindow(this); savePopWindow.ShowDialog(); if (savePopWindow.Chosen == SaveOrNot.Cancel) { return; } else if (savePopWindow.Chosen == SaveOrNot.Save) { SaveFile(this, null); } } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "文本文档|*.txt|所有文件|*.*"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FilePath = openFileDialog.FileName; FileName = openFileDialog.SafeFileName; } else { return; } FileStream file = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite); StreamReader fileReader = new StreamReader(file, System.Text.Encoding.Default); NotepadTextBox.Text = fileReader.ReadToEnd(); this.IsEdited = false; UpdateTitleBar(); }
private void OpenDropedInFile(object sender, System.Windows.DragEventArgs e) //文件拖入窗口 { if (IsEdited == true) { SavePopWindow savePopWindow = new SavePopWindow(this); savePopWindow.ShowDialog(); if (savePopWindow.Chosen == SaveOrNot.Cancel) { return; } else if (savePopWindow.Chosen == SaveOrNot.Save) { SaveFile(this, null); } } FilePath = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(0).ToString(); //System.Windows.MessageBox.Show(FilePath); FileName = FilePath.Substring(FilePath.LastIndexOf("\\") + 1); FileStream file = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite); StreamReader fileReader = new StreamReader(file, System.Text.Encoding.Default); NotepadTextBox.Text = fileReader.ReadToEnd(); this.IsEdited = false; UpdateTitleBar(); }
private void MainWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) //主窗口关闭 { if (IsEdited == true) { SavePopWindow savePopWindow = new SavePopWindow(this); savePopWindow.ShowDialog(); if (savePopWindow.Chosen == SaveOrNot.Cancel) { e.Cancel = true; return; } else if (savePopWindow.Chosen == SaveOrNot.Save) { SaveFile(this, null); } } }
private void NewFile(object sender, RoutedEventArgs e) //菜单-文件-新建 { if (IsEdited == true) { SavePopWindow savePopWindow = new SavePopWindow(this); savePopWindow.ShowDialog(); if (savePopWindow.Chosen == SaveOrNot.Cancel) { return; } else if (savePopWindow.Chosen == SaveOrNot.Save) { SaveFile(this, null); } } this.NotepadTextBox.Text = ""; this.FileName = "无标题"; this.FilePath = ""; this.IsEdited = false; this.UpdateTitleBar(); }