带有功能区的 Visual Studio 图像 (XML)

发布于 2024-11-30 21:29:58 字数 894 浏览 1 评论 0原文

我正在制作 Office 2007 插件,并且尝试使用 XML 而不是视觉设计器来自定义功能区,但由于某种原因我无法获取与之配合使用的图像...您到底需要做什么‽ 我添加了一个名为 Icon1 的资源 png 并尝试了这个:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
      <ribbon startFromScratch="false">
        <tabs>
          <tab id="TabToolss" label="Tools">
            <group id="MyGroup" label="My Group" visible="true">
              <button
                id="Button1"
                image="WordAddIn1.Properties.Resources.Icon1"
                onAction="Button1_Click"
                showImage="true"
                />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

不走运...不知道为什么。即使我将完整的文件路径放在那里也不起作用。

我从来没有让它工作过一次,所以也许我只是没有按照它的方式去做......

I'm making Office 2007 addins and I'm trying to use XML instead of the visual designer to customize the ribbon but for some reason I cant get an image to work with it... What exactly do you have to do‽ I added a resource png called Icon1 and tried this:

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
      <ribbon startFromScratch="false">
        <tabs>
          <tab id="TabToolss" label="Tools">
            <group id="MyGroup" label="My Group" visible="true">
              <button
                id="Button1"
                image="WordAddIn1.Properties.Resources.Icon1"
                onAction="Button1_Click"
                showImage="true"
                />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

No luck... not sure why. Even if I put the full file path in there it doesn't work.

I've never gotten it to work once, so maybe I'm just not doing it the way it was made to be done...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋心╮凉 2024-12-07 21:29:58

非常复杂的解决方案...幸运地在这里找到它

首先 在 CustomUI 选项卡中添加 loadImage 属性,

然后为了简化事情,添加这个内部类

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);
        }
    }

下一步添加 loadImage 函数的定义,

public IPictureDisp Ribbon_LoadImage(string imageName)
        {
            return PictureConverter.ImageToPictureDisp((Bitmap)Resources.ResourceManager.GetObject(imageName));
        }

Very complicated solution... lucky to find it here

First add loadImage attribute to CustomUI tab,

Then to simplify things, add this internal class

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);
        }
    }

Next add definition of loadImage function,

public IPictureDisp Ribbon_LoadImage(string imageName)
        {
            return PictureConverter.ImageToPictureDisp((Bitmap)Resources.ResourceManager.GetObject(imageName));
        }
农村范ル 2024-12-07 21:29:58

如果你执行以下代码,那就容易多了:

<?xml version="1.0" encoding="UTF-8"?> 
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"onLoad="Ribbon_Load>
 <ribbon startFromScratch="false">
   <tabs>
     <tab id="TabToolss" label="Tools">
      <group id="MyGroup" label="My Group" visible="true">
       <button id="Button1" size="normal" getImage="Icon1"
        onAction="Button1_Click"
        showImage="true"/>
    </group>
  </tab>
 </tabs>
</ribbon>

在功能区 cs 中:

namespace Add_in
{
[ComVisible(true)]
public class MyRibbon : Office.IRibbonExtensibility
{
    private Office.IRibbonUI ribbon;

    public MyRibbon()
    {

    }

    public Bitmap Icon1(Office.IRibbonControl control)
    {
        return (Bitmap)Properties.Resources.ResourceManager.GetObject("Icon1");
    }

its a lot easier if you do the following code:

<?xml version="1.0" encoding="UTF-8"?> 
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"onLoad="Ribbon_Load>
 <ribbon startFromScratch="false">
   <tabs>
     <tab id="TabToolss" label="Tools">
      <group id="MyGroup" label="My Group" visible="true">
       <button id="Button1" size="normal" getImage="Icon1"
        onAction="Button1_Click"
        showImage="true"/>
    </group>
  </tab>
 </tabs>
</ribbon>

in the Ribbon cs:

namespace Add_in
{
[ComVisible(true)]
public class MyRibbon : Office.IRibbonExtensibility
{
    private Office.IRibbonUI ribbon;

    public MyRibbon()
    {

    }

    public Bitmap Icon1(Office.IRibbonControl control)
    {
        return (Bitmap)Properties.Resources.ResourceManager.GetObject("Icon1");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文