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
5,824 times
Add to favorites
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()

        private void insertButton_Click(object sender, EventArgs e)
                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);
            catch (COMException ex)