Sunday, June 13, 2010

Ribbion XML and window for

Loading Winform from ribbion Xml in vsto2007

So Let Start...

Requirement :-
Vs2008(vsto)
and Bit of interest

Start:-

For simple Ribbion customization in Vsto..

http://msdn.microsoft.com/en-us/library/aa942955.aspx

Chk The above link.

Know we will START with loading a WIN FORM ribbion and do the same functionality as in above link.


Know Once u ad Modify the Follwing Files MyRibbon.xml,MyRibbon.cs,ThisAddIn.cs

MyRibbion.xml

>?xml version="1.0" encoding="UTF-8"?&lft
>customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
>ribbon>
>tabs>
>tab idMso="TabAddIns">
>group id="ContentGroup" label="Content">
>button id="Loadform" label="Load Form"
screentip="Load Form"
onAction="LoadForm"
supertip="Load Form "/>

>/group>
>/tab>

>/tabs>
>/ribbon>
>/customUI>


MyRibbon.cs
namespace NewRibbionTest
{
[ComVisible(true)]
public class MyRibbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;

public MyRibbon()
{
}

/// This Functin is called from Ribbion and Load the win form
public void LoadForm(Office.IRibbonControl control) { MyTable mytable = new MyTable(); mytable.ShowDialog(); }




#region IRibbonExtensibility Members

public string GetCustomUI(string ribbonID)
{
return GetResourceText("NewRibbionTest.MyRibbon.xml");
}

#endregion

#region Ribbon Callbacks
//Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1

public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
}

#endregion

#region Helpers

private static string GetResourceText(string resourceName)
{
Assembly asm = Assembly.GetExecutingAssembly();
string[] resourceNames = asm.GetManifestResourceNames();
for (int i = 0; i < resourcereader =" new" style="font-weight: bold;">ThisAddIn.cs

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new MyRibbon();
}

Now addding Window form in project and some code

Code Below:-


private void button1_Click(object sender, EventArgs e)
{
object missing = System.Type.Missing; Range currentRange = Globals.ThisAddIn.Application.Selection.Range; Table newTable = Globals.ThisAddIn.Application.ActiveDocument.Tables.Add( currentRange, 3, 4, ref missing, ref missing); // Get all of the borders except for the diagonal borders. Microsoft.Office.Interop.Word.Border[] borders = new Border[6]; borders[0] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft]; borders[1] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight]; borders[2] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop]; borders[3] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom]; borders[4] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal]; borders[5] = newTable.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical]; // Format each of the borders. foreach (Border border in borders) { border.LineStyle = WdLineStyle.wdLineStyleSingle; border.Color = WdColor.wdColorBlue; } this.Hide();

}

private void button2_Click(object sender, EventArgs e)
{
Range currentRange = Globals.ThisAddIn.Application.Selection.Range; currentRange.Text = "This text was added by the Win form."; this.Hide();
}

When you click On Insert Ribbion Button You will get the follwing output












No comments:

Post a Comment