Word.ControlCollection in an ActionPane

Hi,

I'm trying to develop an Action Pane with a button, this button should create an object like a Textbox in the Application.ActiveDocument. I found in msdn some information about the class Word.ControllCollection that should be right for me (I Hope ). But when I use the method AddTextBox it crash. I supposed that it happens because I'm running it in the ActionPane class.
Is it right Is there any workaround

Thanks a lot.


Answer this question

Word.ControlCollection in an ActionPane

  • MauriceSibrandi

    Sorry, I forgot....

    Develop Environment VStudio 2005
    Language VB
    VSTO Version 2005

  • Marcin Książek

    Great, It works fine!!

    Thanks for all

  • c_shah

    Without seeing the code, its hard to determine what the problem is. I have an example of doing this in my book (VSTO for Mere Mortals), but since the book hasn't been published yet, I'll share a bit of the code here for you.

    Things to keep in mind are:

    • Rather than using ActiveDocument, you should use ThisDocument, which you can access from the user control by using the Globals class.
    • This code adds the textbox to the current selection to give the user the opportunity to choose where in the document the textbox is added.
    • Control names must be unique, so I've incremented the name of each control added by counting the total number of controls in the document.

    If you have a button on a user control that you add to the actions pane, you can add the following code to the user control:

    Public Class UserControl1

    Dim ControlCounter As Integer = 0

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Dim Selection As Word.Selection = _
    Globals.ThisDocument.Application.Selection

    Dim ControlName As String = "Control" & _
    ControlCounter.ToString()

    ControlCounter += 1

    Globals.ThisDocument.Controls _
    .AddTextBox(Selection.Range, 100, 50, ControlName)

    End Sub

    End Class

    I hope this helps!

    Kathleen McGrath
    http://blogs.msdn.com/kathleen



  • elgor

    What you are describing should work fine.
    Is the document you are adding to protected if so you will need to programatically unprotect it.




  • Word.ControlCollection in an ActionPane