Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-30-2021, 11:32 PM
Tycho Tycho is offline How to insert custom control into Office Word document - VSTO Windows 10 How to insert custom control into Office Word document - VSTO Office 2019
Novice
How to insert custom control into Office Word document - VSTO
 
Join Date: Mar 2021
Posts: 2
Tycho is on a distinguished road
Question How to insert custom control into Office Word document - VSTO

I want to insert my custom control into the currently opened Word document using VSTO. I have an application that communicates with my already existing VSTO Word plugin over COM. So far I have been using a workaround where I inserted pictures of my custom control as an InlineShape (as images) into the document. This was fine for now, since Word was automatically saving it inside the document, took care of resizing, deleting with the delete key, drag dropping image as a single character, and so on... But now I am encountering some problems regarding adding new functionalities (eg. Right-click on control (image) click). Now I am looking for an alternative, how to insert custom control (probably an ActiveX control?) . I have created an example when i insert a custom control with the Microsoft.Office.Tools.Word.Document.Controls.AddC ontrol() function, but here are some problems:

The control can not be dragged around the range of the document


The control is not saved when the document is closed and reopened
Control does not work when the document zoom is not 100%
See the picture below:


I have also noticed, that i can insert an object into the current word document (insert -> object -> eg. Microsoft Word Document, see picture below)


This inserted object has all the functionality which i need (drag-drop as a single character, saving on document close, resize, functionality when document zoom is not 100%,...) This is exactly what i want to achieve, but instead of another Microsoft Word object, I would like to display my custom control. See the picture below for comparison between MS Word Document object and my custom control inside opened document:


Now i have already spent quite some time googling and doing the research but i am running out of ideas on how to successfully create this to work... If anyone is familiar with the solution of could provide any details on it, it would be extremelly helpful! I have also tried doing something with the new plugins Office add-ins, but keep in mind that i am developing a Windows app, i do not need crossplatform functionality and Word plugin needs to be accessible from the other app (just like current solution, where i access it using COM). Hopefully the explanation was clear enough, i am more than ready to provide additional information if needed!
Reply With Quote
  #2  
Old 03-31-2021, 04:41 AM
Charles Kenyon Charles Kenyon is offline How to insert custom control into Office Word document - VSTO Windows 10 How to insert custom control into Office Word document - VSTO Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Here is a page on using vba to insert a Content Control.
Content Controls for macOS - Cool Code - Brandwares

Even though the article is for a Mac, the vba will work in a Windows environment.
If this is for an image, you may want the picture content control.
OOXML Hacking: Custom Picture Content Controls - Brandwares
Reply With Quote
  #3  
Old 03-31-2021, 07:59 AM
Charles Kenyon Charles Kenyon is offline How to insert custom control into Office Word document - VSTO Windows 10 How to insert custom control into Office Word document - VSTO Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Cross-posted at How to insert custom control into Office Word document - Super User.

I know that this is troubling you and you are eager to get an answer. I gave you a link to several sites appropriate for your question and urged you to only post on one.

For cross-posting etiquette, please read: A Message to Forum Cross-Posters https://web.archive.org/web/20201027...ontent.php?184
Reply With Quote
  #4  
Old 03-31-2021, 11:22 PM
Tycho Tycho is offline How to insert custom control into Office Word document - VSTO Windows 10 How to insert custom control into Office Word document - VSTO Office 2019
Novice
How to insert custom control into Office Word document - VSTO
 
Join Date: Mar 2021
Posts: 2
Tycho is on a distinguished road
Default

I have removed the post from the superuser to prevent cross-posting. I have read the article about it and couldn't agree more. This is something I will definitely keep in mind before asking my next question. Hopefully, you will still take some time to discuss this topic.
As per the link you provided, thank you! I have read them and I want to let you know, that I was already familiar with Picture Content Control (PCC). And if I understand correctly, what you suggest is to use PCC to only display an image of my "custom control"? Is using a PCC the "best" or the most "correct" way of doing this?
Like for example, if I want to add right-click functionality to my "custom control" and extend the context menu to have another context menu item. Another example would be double-clicking. Yeah, sure I can catch a double click event on the document and somehow find out if the correct PCC was double-clicked, but I would imagine being able to handle those events on my control so I would not be needing handling the double click on Word.Document class. Perhaps I misunderstand something, I am really not so familiar with the VSTO plugin development. I just want to find the best practice to be able to extend the functionality further through the years and prevent the situation where I will have to rewrite everything in a few years.
Reply With Quote
  #5  
Old 04-01-2021, 09:24 AM
Charles Kenyon Charles Kenyon is offline How to insert custom control into Office Word document - VSTO Windows 10 How to insert custom control into Office Word document - VSTO Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I am not knowledgeable about VSTO. I am understanding that you want to insert a control to let the user insert an image. The PCC is what you want, not to show a picture of a control, but as a control. Perhaps I am misunderstanding.

I am moving this into the vba forum which is the one most closely related to VSTO.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I insert a line /specify a custom colour using office online pakoul Word 1 10-22-2019 05:34 AM
Word VSTO Content Control binding to XML issue phyrjc Word 0 03-25-2019 08:56 AM
How to insert custom control into Office Word document - VSTO Create Custom Document Properties with Content Control kschmidt Word VBA 7 02-04-2019 03:09 PM
Word 2017 + VSTO 2015 events ArtKilp Word VBA 0 11-20-2018 08:57 AM
How to insert custom control into Office Word document - VSTO Insert image based on document custom property anandyrh Word 1 08-14-2013 12:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft