Creating a Ribbon
By: Vivek Thangaswamy
Page 2 of 2
Date Created: March 23rd 2009
Last Updated: March 23rd 2009
- Next, select the User Control, and name it UserControl1.cs.
- Open the UserControl1.cs file, and add the following namespace references:
using System.Windows.Forms; using Office = Microsoft.Office.Core; using PowerPoint = Microsoft.Office.Interop.PowerPoint;
- Open the Ribbon1.cs fi le, and add the following namespace references:
using System.Windows.Forms; using Office = Microsoft.Office.Core; using PowerPoint = Microsoft.Office.Interop.PowerPoint;
- Next, add the instance of the User Control and custom task pane to the Ribbon code file:
// Usercontrol instance to access from the Ribbon private UserControl1 PacktUserControl; // Instance for Custom Task Pane to create private Microsoft.Office.Tools.CustomTaskPane PacktCustomPane;
- Next, write the following code to show the custom task pane in the button click event of the Ribbon menu:
private void RibbonButton1_Click(object sender, RibbonControlEventArgs e) { // Initializing the UserControl in the ribbon PacktUserControl = new UserControl1(); // Add the UserControl to the custom task pane PacktCustomPane = Globals.ThisAddIn.CustomTaskPanes. Add(PacktUserControl, "Calendar"); // Set the custom task pane to visible PacktCustomPane.Visible = true; } - On the ValueChanged event of the dateTimePicker , we are writing the code to insert the selected date.
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { try { // Getting the active presentation slide PowerPoint.Slide PckTSlide = Globals.ThisAddIn. Application.ActivePresentation.Slides[1]; // Set the presentation type like text or image imsert option PacktTextShape = PckTSlide.Shapes.AddTextbox(Office. MsoTextOrientation.msoTextOrientationHorizontal, 50, 100, 600, 50); // Set the text value as selected date time PacktTextShape.TextFrame.TextRange.Text = dateTimePicker1. Value.ToString(); // Font style properties PacktTextShape.TextFrame.TextRange.Font.Size = 48; PacktTextShape.TextFrame.TextRange.Font.Color.RGB = Color. DarkViolet.ToArgb(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }