添加自定义图像到按钮,在Excel功能区 [英] Add Custom Image to button in excel ribbon

查看:490
本文介绍了添加自定义图像到按钮,在Excel功能区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Microsoft Excel插件,并添加一个按钮,但我需要自定义图像添加到它。如何做到这一点。



 <按钮ID =customButton1标签=myLabel大小=大形象=? ??? /> 


解决方案

尝试在代码隐藏使用此代码片段:

  customButton1.Image =新位图(image.jpg文件); 

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

如何添加自定义图标到工具栏和菜单项




  1. 创建一个名为ConvertImage新类。这个类使用System.Forms.Axhost转换的图像文件可以被施加到菜单项的图像类型。


  2. 添加的方法来转换图标将其添加到一个ImageList文件转换为图像文件。此代码发送映像文件到您创建的ConvertImage.Convert方法,然后返回文件给调用者。



I'm developing a microsoft excel addin and added a button, but I need to add custom image to it. 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. This class uses System.Forms.Axhost to convert an image file to an image type that can be applied to the menu item.

  2. Add a method to convert the icon file into an Image file by adding it to an ImageList. This code sends the Image file to the ConvertImage.Convert method you created and then returns the file to the caller.

这篇关于添加自定义图像到按钮,在Excel功能区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆