/// <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 PasteToolStripButton_Click(object sender, EventArgs e) { try { if (Clipboard.ContainsText()) { RichTextBox1.Paste(); } } catch { return; } }
private void OnPaste(object sender, ExecutedRoutedEventArgs e) { //提取剪贴板数据 IDataObject dataObject = Clipboard.GetDataObject(); //检查数据是否为设备无关位图 if (dataObject != null && dataObject.GetData(DataFormats.Dib) != null) { //将Dib转换为Bitmap Stream imageData = Clipboard.GetDataObject().GetData(DataFormats.Dib) as Stream; System.Drawing.Bitmap bmp = MySuperEditorHelper.CreateBitmapFromDib(imageData); //创建WPF的Image控件,并将其插入到当前光标位置 System.Windows.Controls.Image imageControl = new System.Windows.Controls.Image(); imageControl.Source = MySuperEditorHelper.BitmapToImageSource(bmp); imageControl.Width = bmp.Width; imageControl.Height = bmp.Height; //如果当前有选中的,则先清空它,之后再插入图片,这样一来,就实现了“替换”的效果 if (String.IsNullOrEmpty(RichTextBox1.Selection.Text) == false) { RichTextBox1.Selection.Text = ""; } InlineUIContainer container = new InlineUIContainer(imageControl, RichTextBox1.Selection.Start); } else { RichTextBox1.Paste(); } if (Clipboard.ContainsData(DataFormats.Bitmap)) { //如果粘贴的是图片,则设置为左对齐(因为默认情况下,粘贴图片是居中对齐) EditingCommands.AlignLeft.Execute(null, RichTextBox1); TextRange selection = RichTextBox1.Selection; //取消选中状态,光标移动到最后 selection.Select(selection.End, selection.End); } }