Task Pane Demo Sample

This sample demonstrates how to create a custom task pane for Microsoft Office Word. The task pane contains a text box and a button. When the user types in the text box and clicks the button, the string in the text box is added to the beginning of the active document.

 
 
 
 
 
5 Star
(1)
5,824 times
Add to favorites
5/13/2011
E-mail Twitter del.icio.us Digg Facebook
// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;

namespace TaskPaneWordAddIn
{
    public partial class SimpleControl : UserControl
    {
        public SimpleControl()
        {
            InitializeComponent();
        }

        private void insertButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(insertTextBox.Text))
                {
                    Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;
                    object start = 0;
                    object end = 0;
                    Word.Range range = (Word.Range)document.Range(ref start, ref end);
                    range.InsertAfter(insertTextBox.Text);
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
    }
}