简体   繁体   English

将自定义图像添加到 Excel 功能区中的按钮

[英]Add Custom Image to button in excel ribbon

I'm developing a microsoft excel addin and added a button, but I need to add custom image to it.我正在开发一个 microsoft excel 插件并添加了一个按钮,但我需要向其中添加自定义图像。 How to achieve that如何实现

  <button id="customButton1" label="myLabel" size="large" image="????" />

Try using this code snippet in the code-behind:尝试在代码隐藏中使用此代码片段:

customButton1.Image = new Bitmap("Image.jpg");

OR要么

customButton1.Image = Image.FromFile(@"C:\Image.jpg");

How to: Add Custom Icons to Toolbar and Menu Items 如何:向工具栏和菜单项添加自定义图标

  1. Create a new class named ConvertImage.创建一个名为 ConvertImage 的新类。 This class uses System.Forms.Axhost to convert an image file to an image type that can be applied to the menu item.此类使用 System.Forms.Axhost 将图像文件转换为可应用于菜单项的图像类型。

  2. Add a method to convert the icon file into an Image file by adding it to an ImageList.添加一个方法,通过将图标文件添加到 ImageList 将其转换为 Image 文件。 This code sends the Image file to the ConvertImage.Convert method you created and then returns the file to the caller.此代码将图像文件发送到您创建的 ConvertImage.Convert 方法,然后将该文件返回给调用者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM