SoftCreator

Hello.

I'm using VSTO SE to create Word 2007 Add-Ins. I created simple test Addin. My menu tab with toggle button and one task pane. If toggle button is pressed, task pane is visible. If released then not. Here is the code:

public partial class ThisAddIn

{

private Microsoft.Office.Tools.CustomTaskPane m_ctp_WorkTime = null;

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

{ this.RemoveWorkTimeTaskPane(); }

public bool WorkTimeTPVisible

{

get {

if (m_ctp_WorkTime != null) return m_ctp_WorkTime.Visible;

return false;

}

set {

if (m_ctp_WorkTime != null) m_ctp_WorkTime.Visible = value;

else if (value) this.AddWorkTimeTaskPane();

}

}

private void AddWorkTimeTaskPane()

{

m_ctp_WorkTime = this.CustomTaskPanes.Add(new WorkTimeControl(), "Set document's working time");

m_ctp_WorkTime.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;

m_ctp_WorkTime.Width = 510;

m_ctp_WorkTime.VisibleChanged += new EventHandler(m_ctp_VisibleChanged);

m_ctp_WorkTime.Visible = true;

}

public void RemoveWorkTimeTaskPane()

{

if (m_ctp_WorkTime == null) return;

this.CustomTaskPanes.Remove(m_ctp_WorkTime);

m_ctp_WorkTime = null;

}

void m_ctp_VisibleChanged(object sender, EventArgs e)

{

this.m_ribbon.Invalidate();

}

private void InternalStartup()

{ this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); }

}



Re: Visual Studio Tools for Office Word AddIn. Task pane and menu for multiple documents.

SoftCreator

[ComVisible(true)]

public class CSIRibbon : Office.IRibbonExtensibility

{

private Office.IRibbonUI m_ribbon;

public CSIRibbon()

{}

public void Invalidate()

{ this.m_ribbon.Invalidate(); }

public string GetCustomUI(string ribbonID)

{ return GetResourceText("CSI.OfficeIntegration.WordAddIns.CSIRibbon.xml"); }

public void OnLoad(Office.IRibbonUI ribbonUI)

{ this.m_ribbon = ribbonUI; }

public Bitmap LoadImage(string imageName)

{

Assembly assembly = Assembly.GetExecutingAssembly();

Stream stream = assembly.GetManifestResourceStream(

"CSI.OfficeIntegration.WordAddIns.Resources." + imageName);

return new Bitmap(stream);

}

public void OnCSIWorkTimeButton(Office.IRibbonControl control, bool isPressed)

{ Globals.ThisAddIn.WorkTimeTPVisible = isPressed;

}

public bool GetCSIWorkTimePressed(Office.IRibbonControl control)

{ return Globals.ThisAddIn.WorkTimeTPVisible; }

private static string GetResourceText(string resourceName)

{

Assembly asm = Assembly.GetExecutingAssembly();

string[] resourceNames = asm.GetManifestResourceNames();

for (int i = 0; i < resourceNames.Length; ++i)

{

if (string.Compare(resourceName, resourceNamesIdea, StringComparison.OrdinalIgnoreCase) == 0)

{

using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNamesIdea)))

{

if (resourceReader != null)

{ return resourceReader.ReadToEnd(); }

}

}

}

return null;

}

}





Re: Visual Studio Tools for Office Word AddIn. Task pane and menu for multiple documents.

SoftCreator

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage">

<ribbon>

<tabs>

<tab id="MyTab" label="My Tab">

<group id="CSIWorkTime" label="CSI Work Time">

<toggleButton id ="CSIWorkTimeButton"

size="large"

label="Worktime"

screentip="Show/hide work time Task Pane"

onAction="OnCSIWorkTimeButton"

image="Date and Time 32 n p.png"

getPressed="GetCSIWorkTimePressed" />

</group>

</tab>

</tabs>

</ribbon>

</customUI>





Re: Visual Studio Tools for Office Word AddIn. Task pane and menu for multiple documents.

SoftCreator

It seems work, but if I open more than one Word's window, it have a strange behavior. If I press my toggle button in any window, it is stay pressed in all other. If released, then it stay released in all other windows. And my task pane appearing just in the first window and not in any other. I want to have independent task pane and buttons behavior in any window.

How can I implement it





Re: Visual Studio Tools for Office Word AddIn. Task pane and menu for multiple documents.

Maarten van Stam

The behaviour you hit here is due to the fact that Word is a SDI application where basically only the first window has the TaskPane available.

In this thread Martin Sawicki (MSFT) explained the lot:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1206919&SiteID=1

In short, you have to handle the switching/toggle of TaskPanes yourself for now ... (see other thread)

-= Maarten =-






Re: Visual Studio Tools for Office Word AddIn. Task pane and menu for multiple documents.

SoftCreator

Thank's for the link. I solved this problem. If anybody more need it, you could find my approach if will follow to Maarten van Stam's link.