How do I set bitmaps for my RibbonUI menu items?

D

David Thielen

Hi;

To give more detail, I have:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="OnLoad" loadImage="LoadImage">
<ribbon>
<tabs>
<tab id="WR_RX_MAIN_MENU" label="AutoTag" visible="true">
<group id="WR_RX_TAGS" label="Tags">
<button id="WR_RX_INSERT_TAG" label="Insert Tag"
onAction="RxInsertTag" getEnabled="IsInsertButtonVisible"
image="element_add.png" size="normal" screentip="Insert a
Windward Reports Tag at the cursor location"/>
....

But this method is never called:
public Bitmap LoadImage(string imageName)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("AutoTag.Resources." +
imageName);

return new Bitmap(stream);
}

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

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

Wei Lu [MSFT]

Hello Dave,

The getImage callback method must return a stdole.IPictureDisp type, so you
usually need to convert your images to this type.

Here is a good example for load custom Image.

internal class PictureConverter : AxHost
{
private PictureConverter() : base(String.Empty) { }

static public stdole.IPictureDisp ImageToPictureDisp(Image image)
{
return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
}

static public stdole.IPictureDisp IconToPictureDisp(Icon icon)
{
return ImageToPictureDisp(icon.ToBitmap());
}

static public Image PictureDispToImage(stdole.IPictureDisp picture)
{
return GetPictureFromIPicture(picture);
}
}

public stdole.IPictureDisp GetImage(string imageName)
{
return
PictureConverter.IconToPictureDisp(Properties.Resources.MyIcon);
}

You could refer this article:

http://msdn2.microsoft.com/en-US/library/aa338202.aspx#OfficeCustomizingRibb
onUIforDevelopers_Runtime

Hope this helps.

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

David Thielen

Hi;

I tried that - my LoadImage method is still never called.

Also, according to the following websites the LoadImage method can return a
Bitmap object:
http://msdn2.microsoft.com/en-us/library/bb462634.aspx
http://msdn.microsoft.com/msdnmag/issues/07/02/RibbonX/default.aspx
http://blogs.msdn.com/jensenh/archive/2006/11/27/ribbonx-image-faq.aspx

But either way, my LoadImage method is never called. How do I determine why
Word is not calling it?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

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

Wei Lu [MSFT]

Hello Dave,

Have you tried to simplize the project and just try to show a button with
Image?

Also, did you compile and add all the image into the resources?

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

Entire customui.xml (first 3 buttons):

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="OnLoad" loadImage="LoadImage">
<ribbon>
<tabs>
<tab id="WR_RX_MAIN_MENU" label="AutoTag" visible="true">
<group id="WR_RX_TAGS" label="Tags">
<button id="WR_RX_INSERT_TAG" label="Insert Tag"
onAction="RxInsertTag" getEnabled="IsInsertButtonVisible"
image="element_add.png" size="normal" screentip="Insert a
Windward Reports Tag at the cursor location"/>
<button id="WR_RX_EDIT_TAG" label="Edit Tag" onAction="RxEditTag"
getEnabled="IsEditButtonVisible"
image="element_add.png" screentip="Edit the Windward Reports Tag
the cursor is on"/>
<button id="WR_RX_DELETE_TAG" label="Delete Tag"
onAction="RxDeleteTag" getEnabled="IsEditButtonVisible"
image="element_add.png" screentip="Delete the Windward Reports Tag
the cursor is on"/>
<separator id="WR_RX_SEP1"/>
<button id="WR_RX_DATA_BIN" label="Data Bin" onAction="RxDataBin"
getEnabled="IsDataBinButtonVisible"
imageMso="ImportMoreMenu" screentip="Bring up the data bin"/>
<button id="WR_RX_SELECT_TAG" label="Select Tag"
onAction="RxSelectTag" getEnabled="IsEditButtonVisible"
screentip="Select the Windward Reports Tag the cursor is on"/>
<button id="WR_RX_VALIDATE_TAG" label="Validate Tags"
onAction="RxValidate" getEnabled="IsEditableButtonVisible"
imageMso="FileCompabilityCheckerWord" screentip="Validate all tags"/>
</group>
<group id="WR_RX_REPORTS_MENU_TAG" label="Run Report">
<button id="WR_RUN_TAG" label="Quick RTF" onAction="RxRun"
getEnabled="IsReadOnlyButtonVisible"
imageMso="WatermarkGallery" screentip="Run and display the report"/>
<button id="WR_REPORT_HTML" label="HTML" onAction="RxRunHtml"
getEnabled="IsReadOnlyButtonVisible"
screentip="Display report as html"/>
<separator id="WR_RX_SEP4"/>
<button id="WR_REPORT_PDF" label="PDF" onAction="RxRunPdf"
getEnabled="IsReadOnlyButtonVisible"
screentip="Display report as pdf"/>
<button id="WR_REPORT_RTF" label="RTF" onAction="RxRunRtf"
getEnabled="IsReadOnlyButtonVisible"
imageMso="FileSaveAsWord97_2003" screentip="Display report as rtf"/>
<button id="WR_REPORT_TEXT" label="TEXT" onAction="RxRunText"
getEnabled="IsReadOnlyButtonVisible"
screentip="Display report as text"/>
<separator id="WR_RX_SEP5"/>
<button id="WR_REPORT_WML" label="XML (Word)" onAction="RxRunWml"
getEnabled="IsReadOnlyButtonVisible"
imageMso="FileSaveAsWordDocx" screentip="Display report as WordML"/>
<button id="WR_REPORT_SML" label="XML (Excel)" onAction="RxRunSml"
getEnabled="IsReadOnlyButtonVisible"
imageMso="FileSaveAsExcelXlsx" screentip="Display report as
SpreadsheetML"/>
<button id="WR_REPORT_XLS" label="XLS" onAction="RxRunXls"
getEnabled="IsReadOnlyButtonVisible"
imageMso="FileSaveAsExcel97_2003" screentip="Display report as xls"/>
</group>
<group id="WR_RX_DATA_MENU_TAG" label="Data">
<button id="WR_RX_DATASOURCES_TAG" label="Data Sources"
onAction="RxDataSourceOptions" getEnabled="IsEditableButtonVisible"
imageMso="DatabaseInsert" screentip="Set Windward Reports data
sources"/>
<button id="WR_RX_MAPLIST_TAG" label="Map && View Lists"
onAction="RxMapOptions" getEnabled="IsEditableButtonVisible"
imageMso="SharePointListsWorkOffline" screentip="Set Windward
Reports map & view lists"/>
<separator id="WR_RX_SEP2"/>
<button id="WR_RX_BEANS_TAG" label="Beans"
onAction="RxBeanOptions" getEnabled="IsEditableButtonVisible"
screentip="Set Windward Reports beans"/>
<button id="WR_RX_DATA_IMPORT" label="Import"
onAction="RxDataImport" getEnabled="IsEditableButtonVisible"
screentip="Import dataset"/>
<button id="WR_RX_DATA_EXPORT" label="Export"
onAction="RxDataExport" getEnabled="IsDatasourceButtonVisible"
screentip="Export dataset"/>
</group>
<group id="WR_RX_TOOLS_MENU_TAG" label="Tools">
<button id="WR_RX_TOOLS_CONVERT" label="Convert Tags"
onAction="RxConvert" getEnabled="IsEditableButtonVisible"
screentip="Convert tags"/>
<button id="WR_RX_REPLACE_CONVERT" label="Replace"
onAction="RxReplace" getEnabled="IsEditableButtonVisible"
imageMso="FindDialog" screentip="Replace text in tags"/>
</group>
<group id="WR_RX_OPTIONS_MENU_TAG" label="Options">
<button id="WR_RX_OPTIONS_TAG" label="Options"
onAction="RxOptions" imageMso="FileProperties" screentip="Set Windward
Reports options"/>
<button id="WR_RX_LICENSE_TAG" label="License"
onAction="RxLicense" imageMso="FileAddDigitalSignature" screentip="Set
Windward Reports license key"/>
<separator id="WR_RX_SEP3"/>
<button id="WR_RX_ABOUT_TAG" label="About" onAction="RxAbout"
imageMso="Info" screentip="Windward Reports version"/>
<button id="WR_RX_HELP_TAG" label="Help" onAction="RxHelp"
imageMso="FunctionsLogicalInsertGallery" screentip="Windward Reports Help"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
 
D

David Thielen

Entire Ribbon code (LoadImage is never called):

public string GetCustomUI(string ribbonId)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream =
assembly.GetManifestResourceStream("AutoTag.net.windward.autotag.word.menu.customui.xml");
StreamReader reader = new StreamReader(stream);
return reader.ReadToEnd();
}

public void OnLoad(IRibbonUI ribbonUI)
{
ribbon = ribbonUI;
}

public Bitmap LoadImage(string imageName)
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("AutoTag.Resources." +
imageName);

return new Bitmap(stream);
}
 
W

Wei Lu [MSFT]

Hello Dave,

I simplify your UI to only one button and use the same Code and I get the
LoadImage work and show the image.

I would like to suggest you add some debug output to verify whether the
LoadImage has been invoked or not.

Also, please make sure you have embedded the image into the resources.
Otherwise, the LoadImage method will not get the image and could not show
up in for the button.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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