用心计较般般错 安心自守事事宽

cgl 坚持、努力终有所获
  新随笔  :: 管理

获取ICommand的图片

Posted on 2016-05-30 18:10  用心计较般般错 安心自守事事宽  阅读(229)  评论(0编辑  收藏  举报
            BarButtonItem item = (BarButtonItem)e.Item;
            System.IntPtr _Handle = (System.IntPtr)(cmd as ICommand).Bitmap;
            if (_Handle.ToInt32() != 0)
            {
                try
                {
                    item.Glyph = System.Drawing.Bitmap.FromHicon((System.IntPtr)(cmd as ICommand).Bitmap);
                }
                catch
                {
                    try
                    {
                        item.Glyph = System.Drawing.Image.FromHbitmap(_Handle);
                    }
                    catch
                    {
                    }
                }
            }