I would like to enable select buttons on a custom ribbon after a user registers. I am having problems getting back to the ribbon load command.
Sub Button_Enabled(control as IRibbonControl)
BtnRegistration.Enabled = False
BtnSetup.Enabled = True
BtnBuild.Enabled = True
End sub
You can't modify ribbons directly, but you can set a getEnabled callback and return a boolean. Here is a C# example, should be simple enough to do the same in VB.
Ribbon XML:
<button idMso="ClearFormatting" getEnabled="HasRegistered" />
Code:
public bool HasRegistered()
{
return User.IsRegistered;
}
Once you have completed registration, invalidate the ribbon.
ribbon.Invalidate(); // all controls
ribbon.InvalidateControl(id); // only one control
Related
I have (quite basic) question about RibbonX callback functions.
I coded some macros with VBA packed in VBA modules and created a ribbon tab by using Office RibbonX Editor.
I created an XML with the editor like so...
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="maintab" label="My Macros">
<group id="g_general" label="General">
<button
id="btn_toggle_confidential"
label="Toggle Confidential"
onAction="Toggle_Confidential_Text"
size="large"
imageMso="MailMergeUpdateLabels"
supertip="Toggles the visibility of the 'confidential' tag in the master and in the title layout." />
...
...for all functions that I want available in the ribbon, such as e.g. :
Sub Toggle_Confidential_Text()
If Has_Confidential_Text() = False Then
MsgBox "ATTENTION! There is no confidential tag in the slide master!"
Exit Sub
End If
' etc...
End Sub
Everything works fine and as expected!
In the "callbacks viewer" of the ribbonX editor I see this:
'Callback for btn_toggle_confidential onAction
Sub Toggle_Confidential_Text(control As IRibbonControl)
End Sub
My question is:
How does this accurately connect the button to the function in my code module? Or is this just some simplified display of the "routing" that is done under the hood?
Is the IRibbonControl parameter automatically passed, even though my own subroutine declaration doesn't mention it?
Can I (or how can I) access the IRibbonControl parameter in my subroutine to interact with the ribbon element? Do I need to redesign my approach and wrap my subroutines or can I just access the parameter, because it's implicitly passed?
It should not work as you say it working... If the callback Sub does not contain control As IRibbonControl it should return an errror: "Wrong number of arguments or invalit property assignment". At least, this was happening when I tried creating the callback Sub without control As IRibbonControl parameter.
For a button control, no parameter is automatically passed. If you make the recommended declaration you can use 'Contol.ID' to have the pressed button name. 'Label' in fact...
You can, but not only knowing the control label. Besides label, it also offers Context and Tag...
I developed a VSTO 4 add-in for Excel. It works perfect, however, I have a button placed in the custom tab of its Ribbon control that is initially disabled.
After clicked other ribbon button in my custom tab, I need to enable the initially disabled button.
I tried with:
btnCancelar.Visible = true;
In the Click event of a button, but button is not shown. The strange thing is that when debugging, it still does not appear, but if a MessageBox is shown, the button get visible at last.
I don't understand this behaviour. How can I enable or disable a ribbon button dynamically by code?
I'm not sure what your language is used in your project, but I guess you can tranform it to your own language used. I'll show the example here in C#:
First you need to implement a so called Callback function in the RibbonXML definition:
<button id="buttonSomething" label="Content" size="large" getVisible="EnableControl"/>
then the next step is to implement the Callback function:
public bool EnableControl(IRibbonControl control)
{
return true; // visible ... false = invisible
}
VSTO will trigger the getVisible Callback and depending on the return value enable or disable the visible state (don't forget to remove any Visible property from the RibbonXML, otherwise the Callback is not triggered)
In case of the Ribbon Designer you need to make sure your Click signature is correct, the easies way to do that is by double clicking the button on the ribbon designer. This will create the Click method for you, for instance:
I created a Ribbon with the Ribbon designer and added two buttons. Double clicked the first button to get an empty method like below, and added the code.
private void button1_Click(object sender, RibbonControlEventArgs e)
{
// Toggle button visibility and make sure the button is enabled
// Visible (obviously) makes it visible, while Enabled is grayed if
// false. You don't need this it is Enabled by default, so just for
// demo purposes
button2.Visible = !button2.Visible;
button2.Enabled = button2.Visible;
// Force Ribbon Invalidate ...
this.RibbonUI.Invalidate();
// Long running proces
}
This worked perfectly for me, so if it doesn't work for you please provide more details of your coding.
I have created a workaround to this.
It was simple. Just started the long running process in different thread. That way, cancel button is shown when it should and then hidden after the process ends.
I used this code to launch the process in the Ribbon.cs code:
btnCancelar.Visible = true;
Action action = () => {
Formatter.GenerateNewSheet(Formatter.TargetType.ImpresionEtiquetas, frm.CustomerID, workbook, btnCancelar);
};
System.Threading.Tasks.Task.Factory.StartNew(action);
And inside the process method I have this code:
public static bool GenerateNewSheet(TargetType type, string customerID, Excel.Workbook workbook, Microsoft.Office.Tools.Ribbon.RibbonButton btnCancelar)
{
try
{
_cancelled = false;
InfoLog.ClearLog();
switch (type)
{
case TargetType.ImpresionEtiquetas:
return GenerateTagPrinting(customerID, workbook);
}
return false;
}
finally
{
btnCancelar.Visible = false;
}
}
The interesting thing here I have discovered is that Excel is thread safe, so it was not necessary to add a synchronization mechanism neither when adding rows in the new sheet nor when setting Visible property to false again.
Regards
Jaime
Hello I'm trying to show/hide formRegion in outlook 2007 at Runtime. I have it showing/hiding with e.Cancel in FormRegionFactory_FormRegionInitializing, but it only refreshes when users selects another email. How do i reach event at runtime or there is a better way of showing/hiding the region in 2007 outlook.
if (Settings.Default.DisplayWhere == "WebBrowser")
{
e.Cancel = true;
}
else if(Settings.Default.DisplayWhere == "Outlook")
{
e.Cancel = false;
}
Yes, you can use the FormRegionInitializing event for hiding the form region at runtime. See How to: Prevent Outlook from Displaying a Form Region for more information.
Also you can set the Visible property of the FormRegion class:
WindowFormRegionCollection formRegions =
Globals.FormRegions
[Globals.ThisAddIn.Application.ActiveInspector()];
formRegions.FormRegion1.Visible = false;
See Accessing a Form Region at Run Time for more information.
You may find the Creating Outlook Form Regions section in MSDN helpful.
I've created my own ribbon toolbar tab with a few buttons. I can add text and similar actions to the document I'm working on. Now I want to add a button that will save the document I'm working on without using the Word save button because I want to set some of the parameters.
Every example I found showed how to save a document that was started by my code (Dim MyDoc As New Word.Application) but when I use such syntax from the ribbon button - ActiveDocument is saying that there is no active document.
Any ideas?
ThisAddIn.vb contains:
Protected Overrides Function CreateRibbonExtensibilityObject() As _
Microsoft.Office.Core.IRibbonExtensibility
Return New MyRibbon()
End Function
MyRibbon.xml is very basic (taken from an MS sample)
<group id="ContentGroup" label="Content">
<button id="textButton" label="Insert Text"
screentip="Text" onAction="OnTextButton"
supertip="Inserts text at the cursor location."
/>
</group>
The new document that you have created is not going to be of type Word.Application. Your ribbon/add-in is running in a current Word.Application context.
If this is indeed what you are doing, you should be creating instances of Word.Document, and saving those.
What exactly is the code you are using to create the document, the ribbon, and save your changes?
I created a outlook add-in using VSTO 2008. I didn't create a separate ribbon/group for this add-in. Instead VSTO automatically create the add-in button in the built-in Ribbon when Outlook starts.
Now how do I customize the tooltip of that add-in icon?
Here is the snippet to add label and icon for my add-in
[Microsoft.Office.Tools.Outlook.FormRegionMessageClass("IPM.Note.DougForm")]
[Microsoft.Office.Tools.Outlook.FormRegionName("Doug.Note.FormTest")]
public class QMemoRegionFactory : QRegionFactory, Microsoft.Office.Tools.Outlook.IFormRegionFactory
{
public DougFormTest()
{
this._Manifest.FormRegionName = "DougForm";
this._Manifest.Icons.Page = global::DougForm.OutlookAddin.Properties.Resources.DougIcon_big;
}
...
Thanks
Does you app generate any ribbon XML that you know of? The property names that can set tooltip text for buttons on a Ribbon are ScreenTip and SuperTip.
Alternatively, create your own custom ribbon XML and set the label, icon, and screentip to be whatever you want.
http://msdn.microsoft.com/en-us/library/aa942866(VS.80).aspx