How do I programmatically change...

J

\Ji Zhou [MSFT]\

Hello Dave,

We need to use the getLabel attribute to set the call back function which
will help us to change the label text dynamically.

I achieve this by using the following xml customization codes
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab id="MyTab" getLabel="GetLabel">
<group id="MyGroup"
label="My Group">
</group>
</tab>
</tabs>
</ribbon>
</customUI>

and the following codes in the Connect.cs file

public Office.IRibbonUI ribbon;
private Word.Application applicationObject;
private bool firstFlag = true;

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

public string GetLabel(Office.IRibbonControl control)
{
if (firstFlag)
{
firstFlag = false;
return "My Default Tab Name";
}

return applicationObject.Selection.Text;
}

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject = application as Word.Application;
applicationObject.WindowSize += new
Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(appl
icationObject_WindowSize);
}

void applicationObject_WindowSize(Microsoft.Office.Interop.Word.Document
Doc, Microsoft.Office.Interop.Word.Window Wn)
{
this.ribbon.Invalidate();
}

I use the WindowSize event as a trigger. Whenever I resize my Word main
window, we call the ribbon.Invalidate function which cause all call back
functions called. Then we can return the expected new Tab label in the
GetLabel function. Note that we can only change the custom tab's label,
rather than the system built-in tab like "TabHome", "TabAddIns"...


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Very easy - thank you.


Hello Dave,

We need to use the getLabel attribute to set the call back function which
will help us to change the label text dynamically.

I achieve this by using the following xml customization codes
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab id="MyTab" getLabel="GetLabel">
<group id="MyGroup"
label="My Group">
</group>
</tab>
</tabs>
</ribbon>
</customUI>

and the following codes in the Connect.cs file

public Office.IRibbonUI ribbon;
private Word.Application applicationObject;
private bool firstFlag = true;

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

public string GetLabel(Office.IRibbonControl control)
{
if (firstFlag)
{
firstFlag = false;
return "My Default Tab Name";
}

return applicationObject.Selection.Text;
}

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode,
object addInInst, ref System.Array custom)
{
applicationObject = application as Word.Application;
applicationObject.WindowSize += new
Microsoft.Office.Interop.Word.ApplicationEvents4_WindowSizeEventHandler(appl
icationObject_WindowSize);
}

void applicationObject_WindowSize(Microsoft.Office.Interop.Word.Document
Doc, Microsoft.Office.Interop.Word.Window Wn)
{
this.ribbon.Invalidate();
}

I use the WindowSize event as a trigger. Whenever I resize my Word main
window, we call the ribbon.Invalidate function which cause all call back
functions called. Then we can return the expected new Tab label in the
GetLabel function. Note that we can only change the custom tab's label,
rather than the system built-in tab like "TabHome", "TabAddIns"...


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top