none
Adding a form or control on MS Word application from an Add-in RRS feed

  • Question

  • Is it possible to add a control or a form that acts the way the ruler acts on MS word from an Add-In ( visual studio Add-In project)? If this is not clear, think of simulating/redesigning the ruler itself by designing it on a visual studio Add-In project.

    Thank you.

    Tuesday, September 22, 2015 6:06 PM

Answers

  • Hi Selam,

    I assume that this used Custom Task Pane. You could create a Custom Task Pane, and then set its location with msoCTPDockPositionTop.

    Here is a simple code and a screenshot about result.

            private MyUserControl myUserControl1;
            private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                myUserControl1 = new MyUserControl();
                myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "My Task Pane");
                //if you do not show up "my task pane", you could use the code below
                //myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, " ");
                myCustomTaskPane.Visible = true;
                myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop;  
                //change height 
                //myCustomTaskPane.Height = 60;
            }
    

    You could refer the link below for more details about creating task pane.

    # Walkthrough: Automating an Application from a Custom Task Pane
    https://msdn.microsoft.com/en-us/library/aa942861.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 30, 2015 6:52 AM

All replies

  • Is it possible to add a control or a form that acts the way the ruler acts on MS word from an Add-In ( visual studio Add-In project)? If this is not clear, think of simulating the ruler itself by designing it on a visual studio Add-In project.

    Thank you.

    Tuesday, September 22, 2015 6:01 PM
  • Hi Selam,

    >> Is it possible to add a control or a form that acts the way the ruler acts on MS word from an Add-In ( visual studio Add-In project)?

    Do you mean you want to add controls on Word from add-in at runtime? Which control you want? In my option, you could add content control, Legacy Forms controls and ActiveX Controls.

    Here is a simple code:

            private void addContentControl_Click(object sender, RibbonControlEventArgs e)
            {
                Selection selection = Globals.ThisAddIn.Application.Selection;
                //content control
                selection.Range.ContentControls.Add(WdContentControlType.wdContentControlRichText);
                selection.MoveRight();
                selection.TypeParagraph();
                //Legacy Forms controls
                selection.FormFields.Add(selection.Range,WdFieldType.wdFieldFormDropDown);
                selection.TypeParagraph();
                //ActiveX Controls
                selection.InlineShapes.AddOLEControl("Forms.ComboBox.1");
            }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 23, 2015 2:55 AM
  • Hi Edward, thanks for your reply. Unfortunately adding controls on the actual document is not what I'm trying to do but rather a set of controls that will float over the document like the built-in formatting popup or just above the document like the ruler. 

    Here's some visual aid for what I'm looking for...

    Best Regards 

    Selam A.


    selam alazar simachew

    Wednesday, September 23, 2015 9:48 AM
  • Thanks Edward for the reply.

    Unfortunately what I'm looking for is not adding the controls on the actual document but rather  something that floats over the document similar to the builtin formatting popup that appears when you select a text or something that can behave the way the ruler behaves.

    Here's a picture that shows what I'm looking for  

    Best Regards,

    Selam A.


    selam alazar simachew


    • Edited by Selam Alazar Wednesday, September 23, 2015 4:11 PM adding a picture
    Wednesday, September 23, 2015 4:10 PM
  • Hi Selam,

    Thanks for your description.

    You can customize the user interface (UI) of Microsoft Office applications by using the Office developer tools in Visual Studio. But your requirement for adding buttons under ruler and popup dialog is not supported. You could refer the link below for supported UI features.

    # Office UI Customization
    https://msdn.microsoft.com/en-us/library/bf08984t.aspx?f=255&MSPPError=-2147217396#Shortcut

    For buttons under ruler, I suggest you use Ribbon tabs and groups for a workaround. Ribbon tabs are stored at the top of document.

    For popup dialog, I suggest you use add commands to shortcut menus for a workaround. A shortcut menu appears when you right-click in a document or an application window.

    # How to: Add Commands to Shortcut Menus
    https://msdn.microsoft.com/en-us/library/dd554969.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, September 24, 2015 6:35 AM
  • Edward thanks for your detailed reply. 

    I found this Add-in on this website office-addin.com

    What the add-in does is, it creates tabs above the document container. It looks to me that the controls are added on the application level. It seems that the tabs are added on application level and they appear in a similar place to where I want mine to be. 

    How can I do something like that? which part of the word object model provides a way to do this?

    Best Regards

    Selam A.


    selam alazar simachew


    Friday, September 25, 2015 3:18 PM
  • Hi Selam,

    I assume that this used Custom Task Pane. You could create a Custom Task Pane, and then set its location with msoCTPDockPositionTop.

    Here is a simple code and a screenshot about result.

            private MyUserControl myUserControl1;
            private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                myUserControl1 = new MyUserControl();
                myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, "My Task Pane");
                //if you do not show up "my task pane", you could use the code below
                //myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, " ");
                myCustomTaskPane.Visible = true;
                myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop;  
                //change height 
                //myCustomTaskPane.Height = 60;
            }
    

    You could refer the link below for more details about creating task pane.

    # Walkthrough: Automating an Application from a Custom Task Pane
    https://msdn.microsoft.com/en-us/library/aa942861.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 30, 2015 6:52 AM