Microsoft Office Tutorials and References
In Depth Information
Creating a Commandbar
Open Visual Studio 2008 to create a new Visio solution, as explained earlier. Write
the following code to create a Commandbar for Visio in the ThisAddIn.cs file.
// Namespace to access Windows Form features
using System.Windows.Forms;
// Instance of the CommandBars collection object
private Office.CommandBars PacktCommandBarCollection;
// Instance of the CommandBar object
private Office.CommandBar PacktCommandBar;
// Instance of CommandBarButton control
private Office.CommandBarButton PacktBookList;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Access the current application's CommandBars
PacktCommandBarCollection = (Office.CommandBars)this.
Application.CommandBars;
// Add the new CommandBar to the CommandBar list with name, type,
and so on.
PacktCommandBar = PacktCommandBarCollection.Add(
"PacktVisioBar", Office.MsoBarPosition.msoBarTop,
Type.Missing, true);
// Add the CommandBarButton to your new CommandBar
PacktBookList = (Office.CommandBarButton)PacktCommandBar.
Controls.Add(Office.MsoControlType.msoControlButton, 1,
Type.Missing,1, true);
// Set tag property to the CommandButton
PacktBookList.Tag = "Packt Book List";
// Set the tooltip property of the CommandButton
PacktBookList.TooltipText = "Made for Packt";
// Register the click event for the button
PacktBookList.Click += new Office.
_CommandBarButtonEvents_ClickEventHandler(
PacktBookList_Click);
}
// Click event of the CommandButton control
private void PacktBookList_Click(Office.CommandBarButton Ctrl,
ref bool CancelDefault)
{
// Message to button clicked users
MessageBox.Show("books are in progress...");
}
 
Search JabSto ::




Custom Search