I've got a Word addin, and I happen to be adding a lot of Windows Forms
controls frequently to the document at runtime. It takes about 3
seconds the first time I call Document.Controls.AddControl(..), with
the Word window flickering, and then takes about 1/2 - 1 second each
additional time I call it.
I realize this isn't the most popular scenario, but I'm wondering if
anyone with inside knowledge can give me some tips on how to make this
a bit faster. I'm willing to do any kind of hack (this is a research
prototype, not production). When I insert the control into the
document, Word reflows its text to make room for the control, so I make
sure the InlineShape gets created as a 1x1 pixel square to minimize
reflow; once it's in the document, I turn its Font.Hidden property to
true so that it doesn't take up any space. It would be great if I could
make the shape's anchoring range hidden _before_ I insert the control,
but I'm not sure if that's possible. Also, the performance hit might be
the creation of the control; I can cache the creation of these ahead of
time if that might help.
I've run the profiler in VS2005 and it seems like all the time spent
adding controls is in some platform calls (not sure what they do), so I
can't really intuit where the cost is coming from. I suspect it's in
generating the OleControl wrapper and is independent of any
optimizations I make, but I'm hoping not.

Increase performance of ControlCollection AddControl in Word
Steve Severance
Hi,
I think the confusion resulted from the term Add-in. In Word, VSTO customizations are integrated with the document and are completely different Add-Ins (COM or Word). Anyway, it sounds like you have created a VSTO customization, so this is an appropriate place to post your question. The bad news is that we can't explain why Word is so slow adding controls, though we can confirm that it is much slower than Excel in the same scenario. We've profiled VSTO code and we don't believe the bottleneck is on our end. In that respect, it might be worth posting in the Word forum as John suggested on the off-hand chance one of the Word experts has some ideas. About the only thing I can think of would be to try turning off screen-updating. Also, if you don't need to use in-line shapes, try adding the controls by positiion (which will use floating Shapes and will eliminate the reflow).
Finally, it would be worthwhile to file a bug on this. You can do so at http://lab.msdn.microsoft.com/ProductFeedback/reportbug/search.aspx. I can't promise that we will be able to fix this (particularly since I'm not sure its a VSTO issue), but the feedback is still valuable because it lets us know that this issue is important.
Sorry, I don't have a better answer for you.
Sincerely,
Geoff Darst
Microsoft VSTO Team
CherylAF
Reformist
(Interesting moniker)
Because you are using a Word add-in, you are using straight VS and not VSTO tools directly as we currently do not have special Word add-in tools. You will most likely get a faster response by posting to a more appropriate forum or ng. I have a great list of Word developer resources (including the reference documentation for the API you are using) here:
http://blogs.msdn.com/johnrdurant/archive/2005/12/16/word_developer_resources.aspx
Best of luck with our solution,
John.
Ju Wu
I'm not sure I understand - my project is a Word template (created with the new project wizards), and ControlCollections are only offered on Office.Word.Tools.Document (as opposed to Office.Word.Interop.Document), which I thought was VSTO. Also, I think the performance issue has to do with the magic under the hood that lets VSTO projects host Windows Forms controls on Word documents, which isn't possible with normal COM add-ins.
Should I still move the question to the word forum Sorry for the confusion.
Pedro Remedios
The best place to post this question is in the office.developer.com_addins newsgroup. Here is the link:
http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US
Thanks!
Mike Hernandez
Community Program Manager
VSTO Team