Saturday, May 15, 2010

VSTo WORD 2007 WITH WORD ADDIN

Using Simple Task pane in Word Addin Sample..

Requirement:-

Interest
Vs2008
and Vsto

Code:-

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddinSample1();
}


//Initlizating the customtaskpane object of the current application
private Microsoft.Office.Tools.CustomTaskPane PacktTaskPaneControl = null;

//Inializing the Usercontrol
UserControl PacktUsercontrol = new UserControl();


public void AddinSample1()
{
//add the TextBox control to the CustomTaskPaqne
//The PacktUserControl parameter sets the title to search
PacktTaskPaneControl = this.CustomTaskPanes.Add(PacktUsercontrol, "Sample Avinash Search");

// Set the CustomTaskPane to visible
PacktTaskPaneControl.Visible = true;



}

Output:-





Word addin with task pane






Code :-

User Control



WordAddIn1.ThisAddIn newtest = new WordAddIn1.ThisAddIn();

int mytestvalue = 0;
mytestvalue = Convert.ToInt16(textBox1.Text) + Convert.ToInt16(textBox2.Text);
string Myvalue = "";
Myvalue = Convert.ToString(mytestvalue);

MessageBox.Show(Myvalue);


Addin Control...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Word;
using Microsoft.Office.Tools.Word.Extensions;
using System.Windows.Forms;

namespace WordAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddinSample1();
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

//Initlizating the customtaskpane object of the current application
private Microsoft.Office.Tools.CustomTaskPane PacktTaskPaneControl = null;

//Inializing the Usercontrol
UserControl PacktUsercontrol = new UserControl();


public void MyTest(string Mytest)
{
// this.Content.InsertAfter(Mytest);

}


public void AddinSample1()
{
//add the TextBox control to the CustomTaskPaqne
//The PacktUserControl parameter sets the title to search
PacktTaskPaneControl = this.CustomTaskPanes.Add(new UserControl1(), "Sample Cal Search");

// Set the CustomTaskPane to visible
PacktTaskPaneControl.Visible = true;



}


#region VSTO generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}
}









No comments:

Post a Comment