/// <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 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> /// <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); }