none
Window ownership in an add-in RRS feed

  • Question

  • Hi there,

    I've written an add-in that uses a couple of Form objects to communicate with the user; I want to have these be owned by the document window they relate to.  However, the Form.Owner property is of type System.Windows.Forms.Form and the document Window collection members are of type Microsoft.Office.Interop.Word.Window.  Somewhat predictably, my naive attempt to cast one to the other failed.

    Is there a conversion or some other way to achieve this?  It seems a little strange that a Form can only be owned by another Form.  If that is indeed the case, can anyone recommend a different class to inherit that allows roughly the same kind of interaction as a Form but can be owned by any other Window?

    I've a notion I'm going to kick myself about this one way or another.

    Thanks!


    Andrew
    _|_.
    |..|
    |_.|_/
    Friday, January 21, 2011 12:23 PM

Answers

All replies

  • Hello Andrew,

    Thanks for posting. Based on my experience, these two classes are totally different and cannot be casted to each other. Please see these two MSDN articles: Form Class and Window Interface.

    To get a better understanding on this issue, would you please clarify some points for us?

    How you use this Form which is of type System.Windows.Forms.Form in this add-in? Is this add-in a VSTO add-in or other else?

    Why do you want to change the owner of the from? What kind of interaction you want?

    Also here is a thread which might help you: http://social.msdn.microsoft.com/forums/en-us/vsto/thread/B77C63A9-5A5C-4280-8865-40D7D098D687.

    If you have any concern on this post, just feel free to follow up. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 25, 2011 11:37 AM
  • Hi there,

    Yes, it is a VSTO add-in (though I'm writing in C# and not VB—my background is in C so it's more comfortable for me!)  Essentially I want the add-in forms to act as dialogs for a specific document.

    The constructor I have for the form currently allows me to pass the word document, a reference to the add-in and various internal data to the form, which then allows the user to do various things to the word document passed by the add-in.  Since each form relates directly to a specific document it would be great to have the document window own the form window, as is the case for dialogs (such as the spell-check dialog in Word).  Unfortunately, as you say, there seems to be no way to cast one to the other, and as it seems only a form can own a form I am at a loss to work out what could bridge the gap!

    Thanks for the thread you sent; my problem is not so much that I'm trying to make a class do the work of an instance, as that my form class inherits the form ownership property and not some other ownership property that would work with Word.  If I could find another windowing class, hopefully one that mainly implements the same kind of methods as a Form class and that would not, therefore, require too much reprogramming, that would be awesome.

    Thanks!


    Andrew
    _|_.
    |..|
    |_.|_/
    Tuesday, January 25, 2011 11:56 AM
  • Hi Andrew

    See if the information on this web page helps:

    http://www.outlooksharp.de/Resources/HowTos/tabid/67/Default.aspx


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by andrewwyld Thursday, January 27, 2011 9:50 AM
    Thursday, January 27, 2011 7:21 AM
    Moderator
  • Perfect. Thank you, I think it would have taken me days to find that.
    Andrew
    _|_.
    |..|
    |_.|_/
    Thursday, January 27, 2011 9:53 AM