void App_WindowBeforeRightClick(Microsoft.Office.Interop.Word.Selection Sel, ref bool Cancel) { var doc = Globals.ThisAddIn.Application.ActiveDocument; try { this.RemoveItem(); this.addmore(); if (Globals.ThisAddIn.Application.Selection.Words.First.Font.Underline == Word.WdUnderline.wdUnderlineWavy) { List <string> seggrsted = this.suggestions(Globals.ThisAddIn.Application.Selection.Words.First.Text); this.AddItem(seggrsted[0]); } } catch (Exception exception) { MessageBox.Show("Error: " + exception.Message); } }
internal void AddPictureContentControl(Utility _utility) { Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument); Microsoft.Office.Interop.Word.Selection selection = this.Application.Selection; if (selection != null && selection.Range != null) { WdSelectionType sel = selection.Type; // inlineshape // if (sel == WdSelectionType.wdSelectionInlineShape) { // InlineShapes shape = vstoDocument.InlineShapes; //shape[0]. MemoryStream ms = new MemoryStream(_utility.BitmapBytes); Image _drawnimage = Image.FromStream(ms); //_drawnimage.Save("temp.jpg"); // Word.ContentControl contentControl = Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTitle(_utility.TagName)[0]; //foreach (Word.ContentControl contentControl in vstoDocument.Content.ContentControls) { // WdContentControlType type = contentControl.Type; //if (type == WdContentControlType.wdContentControlPicture && contentControl.Tag.Equals(_utility.TagName)) { //object missing = Type.Missing; //Microsoft.Office.Interop.Word.ContentControl contentControl = vstoDocument.ContentControls.Add(WdContentControlType.wdContentControlPicture, // ref missing); //contentControl.Range.InlineShapes.AddPicture("temp.jpg", ref missing, ref missing, // ref missing); //contentControl.Title = "violet"; Microsoft.Office.Interop.Word.ContentControl cp2 = selection.Range.ParentContentControl; if (cp2 != null)//update { CustomXMLPart xmlpart = vstoDocument.CustomXMLParts.SelectByID(cp2.Tag); xmlpart.Delete(); cp2.Delete(); } CustomXMLPart cp = vstoDocument.CustomXMLParts.Add(_utility.xml); PictureContentControl piccontrol = vstoDocument.Controls.AddPictureContentControl(selection.Range, Guid.NewGuid().ToString()); piccontrol.Image = _drawnimage;// ScaleImage(_drawnimage, 200, 150);//Save(new Bitmap(returnImage), 270, 180, 0); piccontrol.Title = "violet"; piccontrol.Tag = cp.Id; } } // vstoDocument.Save(); ms.Flush(); ms.Close(); } } }