How can I set a ribbon control’s status programmatically?
Locked
-
Sunday, February 08, 2009 12:38 PMModerator
How can I set a ribbon control’s status programmatically?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Edited by Ji.ZhouModerator Wednesday, February 11, 2009 12:48 PM
- Edited by Ji.ZhouModerator Saturday, February 14, 2009 1:12 AM
All Replies
-
Sunday, February 08, 2009 12:39 PMModerator
This depends on how we create the ribbon, by the Visual Designer or the Ribbon xml customization.
1. If we use the Visual Designer to create the ribbon, we can access the ribbon and its controls via Globals.Ribbons. Take the toggle button for an example, we use the following codes to set its status to be pressed:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Globals.Ribbons.Ribbon1.toggleButton1.Checked = true;
}
2. If we use the xml file to customize the Ribbon, we need to write the corresponding call back function for that control. We still take the toggle button as an example, we can define toggle button’s getPressed call back function as follows:
<toggleButton id="toggleButton1" label="toggleButton1" size="large" getPressed ="get_Pressed" />
Then we implement the get _Pressed like the following. When the function returns true, the toggle button will be in pressed status. While it returns false, the toggle button will be in an unpressed status. We can call ribbon.Invalidate() anywhere to enforce the call back function to get executed.
public bool get_Pressed(Office.IRibbonControl control)
{
if (Globals.ThisAddIn.ctp.Visible)
{
return true;
}
else
{
return false;
}
}
(Related forum thread http://social.msdn.microsoft.com/forums/en-US/vsto/thread/2f1e4fb1-8de2-4ac0-887d-b48013e7c274/ )
For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by Ji.ZhouModerator Wednesday, February 11, 2009 12:49 PM
-
Wednesday, April 01, 2009 12:01 PMModeratorAdd VB version codes,
Public Function get_Pressed(ByVal control As Office.IRibbonControl) As Boolean
If Globals.ThisAddIn.ctp.Visible Then
Return True
Else
Return False
End If
End Function
We have published a VSTO FAQ recently, you can view them from the entry thread http://social.msdn.microsoft.com/Forums/en/vsto/thread/31b1ffbf-117b-4e8f-ad38-71614437df59. If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.

