/// <summary> /// 关闭前处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window1_OnClosing(object sender, CancelEventArgs e) { //保存所有便签设置 NotepadManage.SaveSetings(this); //Application.Current.MainWindow try { RichTextBoxTool.Writer(RichTextBox1, CacheFileName); //如果ShowInTaskbar设置为true,则关闭时先关闭子窗体 //如果设置为false,则先关闭主窗体 //if (!ShowInTaskbar) NotepadManage.RemoveNotepad(this); NotepadManage.ShowWindowListCount--; if (NotepadManage.ShowWindowListCount == 0) { //关闭一个应用程序。 SystemCommon.ExitSystem(); } } catch (Exception ex) { MessageBox.Show("保存出了点问题..." + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error); e.Cancel = true; } }
/// <summary> /// 设置标题 /// </summary> private void SetCaption() { string resutStr = RichTextBoxTool.StringFromRichTextBox(RichTextBox1); if (string.IsNullOrEmpty(resutStr) || resutStr == Environment.NewLine) { return; } try { string[] strs = resutStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); resutStr = strs[0]; if (resutStr.Length < 10) { Caption = resutStr; } else { Caption = resutStr.Substring(0, 10); } this.Title = Caption; } catch (Exception) { return; } }
/// <summary> /// 关闭时缓存数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WindowConvenienceSticker_OnClosing(object sender, CancelEventArgs e) { if (!string.IsNullOrEmpty(CacheFileName)) { RichTextBoxTool.Writer(RichTextBox1, CacheFileName); } }
/// <summary> /// 加载已经缓存的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WindowConvenienceSticker_OnLoaded(object sender, RoutedEventArgs e) { if (File.Exists(CacheFileName)) { RichTextBoxTool.Read(RichTextBox1, CacheFileName); } }
/// <summary> /// 关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnClose_OnMouseUp(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) { return; } //如果是空内容,关闭不提示 string resutStr = RichTextBoxTool.StringFromRichTextBox(RichTextBox1); if (string.IsNullOrEmpty(resutStr) || resutStr == Environment.NewLine) { Close(); if (File.Exists(CacheFileName)) { File.Delete(CacheFileName); } return; } WindowMessage windowMessage = new WindowMessage("删除", "隐藏", "取消"); windowMessage.Text = "确认删除或隐藏?删除之后可在回收站中查找。"; windowMessage.Title = "确认删除或隐藏"; windowMessage.ShowDialog(); //保存所有便签设置 NotepadManage.SaveSetings(this); string ret = windowMessage.OperatingButton; switch (ret) { case "删除": Close(); //移动 File.Move(CacheFileName, RichTextBoxTool.PathCacheDelete + Path.GetFileName(CacheFileName)); break; case "隐藏": Close(); //移动 File.Move(CacheFileName, RichTextBoxTool.PathCacheHidden + Path.GetFileName(CacheFileName)); break; case "取消": return; break; } }
/// <summary> /// 事件--操作事件包括 添加提醒,添加确认,添加序号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MenuItemOperating_OnClick(object sender, RoutedEventArgs e) { string header = ((System.Windows.Controls.HeaderedItemsControl)sender).Tag.ToString(); switch (header) { case "添加确认": SetCheck(); break; case "添加图片": AddImage(RichTextBox1); break; case "添加提醒": SetRemind(); break; case "发送给": var v = new StringCollection(); v.Add(CacheFileName); Clipboard.SetFileDropList(v); MessageBox.Show("复制成功,快去聊天工具上粘贴吧Ctrl+C", "发送给...", MessageBoxButton.OK, MessageBoxImage.Information); break; case "去格式粘贴": //Class1.Text(); //pgn,jpg两种格式FileDrop if (Clipboard.ContainsFileDropList()) { e.Handled = true; StringCollection stringCollection = Clipboard.GetFileDropList(); foreach (string s in stringCollection) { //如果是图片,则导入图片 RichTextBoxTool.RichTextBoxAddImage(RichTextBox1, s, image_MouseDown); } ; } else if (Clipboard.ContainsText()) { e.Handled = true; string paste = Clipboard.GetText(); Clipboard.SetText(paste); RichTextBox1.Paste(); Clipboard.Clear(); } break; } }
private void btnFind_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(txtContent.Text.Trim())) { RichTextBoxTool.FindText(rtxtBox, txtContent.Text.Trim(), rbtnNext.Checked?RichTextBoxFinds.None:RichTextBoxFinds.Reverse); } else { MessageBox.Show("请向输入查询内容"); } }
private void BtnAddImage_OnClick(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = "*.png|*.jpg"; ofd.Filter = "png file|*.png|jpg file|*.jpg"; if (ofd.ShowDialog() == false) { return; } //添加图片 RichTextBoxTool.RichTextBoxAddImage(RichTextBox1, ofd.FileName, image_MouseDown); }
/// <summary> /// 绑定列表 /// </summary> private void BingListBox1() { List <ListBoxItemM> list = new List <ListBoxItemM>(); List <string> files = new List <string>(Directory.GetFiles(_selectedPath, SystemCommon.SearchExtensionName)); foreach (string f in files) { list.Add(new ListBoxItemM() { Name = Path.GetFileName(f), Text = RichTextBoxTool.StringFromFlowDocument(f) }); } ListBox1.ItemsSource = list; }
/// <summary> /// 图片插入 /// </summary> /// <param name="rtbInfo"></param> /// <returns></returns> public bool AddImage(System.Windows.Controls.RichTextBox rtbInfo) { Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); ofd.DefaultExt = "*.png|*.jpg"; ofd.Filter = "png file|*.png|jpg file|*.jpg"; if (ofd.ShowDialog() == false) { return(false); } //添加图片 RichTextBoxTool.RichTextBoxAddImage(RichTextBox1, ofd.FileName, image_MouseDown); rtbInfo.Focus(); return(true); }
/// <summary> /// 设置提醒-手动设置 /// </summary> private void SetRemind() { string resutStr = RichTextBoxTool.StringFromRichTextBox(RichTextBox1); string[] strs = resutStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (strs.Length == 0) { resutStr = ""; } WindowRemind windowRemind = new WindowRemind(resutStr, WindowSettings.RemindDateTime, _cancellationTokenSource); windowRemind.RemindDateTime = WindowSettings.RemindDateTime; windowRemind.RemindAction += RemindAction; windowRemind.ShowDialog(); if (windowRemind.IsSave) { WindowSettings.RemindDateTime = windowRemind.RemindDateTime; } }
/// <summary> /// 窗体加载,打开所有便签 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { //加载设置 _settings.Reload(); Title = _settings.Title; Left = _settings.WinLocation.X; Top = _settings.WinLocation.Y; RichTextBoxTool.AddExtenstion(); NotepadManage.OpenAllNotepad(); Top = -500; Left = -500; //设置主窗体 SystemCommon.SetWindowMain(this); //设置主窗体 ShowInTaskbar = !NotepadManage.SystemSetting.ShowInTaskbar; //打开导入的文件 NotepadManage.OpenImputFileTask(); }
/// <summary> /// 窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window1_OnLoaded(object sender, RoutedEventArgs e) { if (File.Exists(CacheFileName)) { RichTextBoxTool.Read(RichTextBox1, CacheFileName); SetCaption(); } SkinM = new SkinManage().GetSkin(WindowSettings.BackColorName); //设置提醒 if (WindowSettings.RemindDateTime != null) { SetRemind((DateTime)WindowSettings.RemindDateTime); } //窗体效果设置 WindowsTool tool = new WindowsTool(this); tool.SetTopAutoShow(GridTitleBottom, GridTitle); tool.SetNotMax(GridTitle); tool.DragMove(GridTitle); RichTextBox1.Focus(); //Visibility = WindowSettings.NotepadState == NotepadState.Visible // ? Visibility.Visible // : Visibility.Collapsed; if (WindowSettings.Left != 0) { Left = WindowSettings.Left; } if (WindowSettings.Left != 0) { Top = WindowSettings.Top; } }
/// <summary> /// 没有焦点时保存,并设置标题 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RichTextBox1_OnPreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { SetCaption(); RichTextBoxTool.Writer(RichTextBox1, CacheFileName); }
/// <summary> /// 鼠标离开时设置标题 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RichTextBox1_MouseLeave(object sender, MouseEventArgs e) { SetCaption(); RichTextBoxTool.Writer(RichTextBox1, CacheFileName); }