visual-studio - Visual Studio 状态栏中的动画图像

标签 visual-studio visual-studio-extensions vsix

下面的文章介绍了如何使用状态栏中内置的 VS 动画图标。

https://msdn.microsoft.com/en-us/library/bb166795.aspx

我想知道,有没有办法在状态栏中包含自定义 gif 动画。

可以像下面一样包含位图图像。

https://social.msdn.microsoft.com/Forums/vstudio/en-US/fef208e7-b79d-4a0c-94fe-e6861196e1f5/how-to-show-my-icon-in-exp-visutal-stufo-statusbarsvsstatusbar?forum=vsx#ba47b61c-77a8-46c8-aa10-a04211312e6c

当我根据上面的示例指向 gif 图像时,动画没有发生。请帮忙。

最佳答案

据我所知,没有任何方法可以直接使用gif动画图像。

正如 IVsStatusbar.Animation提到的方法:

[in] If the VARIANT is a VT_I2, it refers to the SBAI_Index of predefined animated icons. If this parameter is a VT_I4, it refers to an HBITMAP containing the filmstrip image for animation, whose width should be a multiple of its height.

您可以将 gif 文件转换为宽度为其高度倍数的 BMP 图像,方法是将 gif 图像的每一帧复制并粘贴到 BMP 文件中,然后使用您提到的第二个链接中提供的代码。

例如,这是我创建的 BMP 图像,其中包含 5 个动画帧:

enter image description here

将此图像保存为BMP文件,使用第二个链接中的代码并调试它:

private void MenuItemCallback(object sender, EventArgs e)
{
    IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar));

    Bitmap b = new Bitmap(@"D:\ani.bmp");
    IntPtr hdc = IntPtr.Zero;
    hdc = b.GetHbitmap();
    object hdcObject = (object)hdc;
    statusBar.Animation(1, ref hdcObject);
    System.Windows.Forms.MessageBox.Show("Click OK to end status bar animation.");
    statusBar.Animation(0, ref hdcObject);
    DeleteObject(hdc);
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);

您将在 Visual Studio 中看到如下动画: enter image description here

关于visual-studio - Visual Studio 状态栏中的动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43091133/

相关文章:

visual-studio - 命名事件处理程序 : How to make the first letter uppercase

c++ - 无法将模板类定义与 Visual Studio 2010 上的主程序链接

c# - Visual Studio SDK - 处理文件添加、删除和重命名事件

c# - 在运行时导出自定义 EditorFormatDefinition

visual-studio-2012 - 使用 WIX 将 VSIX 安装到 Visual Studio 11.0 和 12.0

visual-studio - 如何调试 Visual Studio 扩展

git - Visual Studio-Azure 开发人员 : failed to push the branch to the remote repository

java - 如何在 Visual Studio 2017 中使用 Java

asp.net-mvc - 在 Visual Studio 中将字符串参数标记为 MVC Controller 或 View 名称

c# - 将 project.json 包引用添加到 VSIX