I want to display a custom chm file when F1 is pressed while the ribbon button tooltip displays "Press F1 for more help". Can you provide me an example ?
The "HelpSource" and "HelpTopic" properties of the RibbonItem class have to be set for AutoCAD to display your chm file. "HelpSource" is the Uri to the chm file and the "HelpTopic" is the topic id of the page in the chm file.
Here is the code snippet. You may need to modify the "HelpSource" and "HelpTopic" strings to point to the chm file in your system and to a topic id in it. Also, add the "AdWindows.dll" to the references in your project
// From AdWindows.dll
using Autodesk.Windows;
public class MyCommands
{
[CommandMethod("CRB")]
public void createRibbonButton()
{
Autodesk.Windows.RibbonControl ribCntrl =
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
//add the tab
RibbonTab ribTab = new RibbonTab();
ribTab.Title = "My custom tab";
ribTab.Id = "MY_TAB_ID";
ribCntrl.Tabs.Add(ribTab);
//create the panel source
Autodesk.Windows.RibbonPanelSource ribSourcePanel
= new RibbonPanelSource();
ribSourcePanel.Title = "Controls";
//now the panel
RibbonPanel ribPanel = new RibbonPanel();
ribPanel.Source = ribSourcePanel;
ribTab.Panels.Add(ribPanel);
Autodesk.Windows.RibbonToolTip ribToolTip
= new RibbonToolTip();
ribToolTip.Command = "My Command";
ribToolTip.Title = "My Title";
ribToolTip.Content = "My Content";
ribToolTip.ExpandedContent = "My Expanded Content !";
// Without this "Press F1 for help" does not appear in the tooltip
ribToolTip.IsHelpEnabled = true;
Autodesk.Windows.RibbonButton ribButton
= new RibbonButton();
ribButton.Text = "PLINE";
ribButton.ShowText = true;
ribButton.CommandParameter = "\x1b\x1b_PLINE ";
ribButton.CommandHandler = new AdskCommandHandler();
ribButton.HelpSource
= new System.Uri(
@"C:\Temp\ToolTipDemo.chm",
UriKind.RelativeOrAbsolute
);
ribButton.HelpTopic = "CreateLayer";
ribButton.IsToolTipEnabled = true;
ribButton.ToolTip = ribToolTip;
ribSourcePanel.Items.Add(ribButton);
ribTab.IsActive = true;
}
}
public class AdskCommandHandler : System.Windows.Input.ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
RibbonButton ribBtn = parameter as RibbonButton;
if (ribBtn != null)
{
Application.DocumentManager.MdiActiveDocument.SendStringToExecute
(
(String)ribBtn.CommandParameter, true, false, true
);
}
}
}