下面的文章介绍了如何使用状态栏中内置的 VS 动画图标。
https://msdn.microsoft.com/en-us/library/bb166795.aspx
我想知道,有没有办法在状态栏中包含自定义 gif 动画。
可以像下面一样包含位图图像。
当我根据上面的示例指向 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 个动画帧:
将此图像保存为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 - Visual Studio 状态栏中的动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43091133/