我使用以下代码来渲染透明图标:
private void button1_Click(object sender, EventArgs e)
{
// using LoadCursorFromFile from user32.dll
var cursor = NativeMethods.LoadCustomCursor(@"d:\Temp\Cursors\Cursors\aero_busy.ani");
// cursor -> bitmap
Bitmap bitmap = new Bitmap(48, 48, PixelFormat.Format32bppArgb);
Graphics gBitmap = Graphics.FromImage(bitmap);
cursor.DrawStretched(gBitmap, new Rectangle(0, 0, 32, 32));
// 1. Draw bitmap on a form canvas
Graphics gForm = Graphics.FromHwnd(this.Handle);
gForm.DrawImage(bitmap, 50, 50);
// 2. Draw cursor directly to a form canvas
cursor.Draw(gForm, new Rectangle(100, 50, 32, 32));
cursor.Dispose();
}
很抱歉,我无法将透明光标渲染为位图!直接将光标绘制到窗体画布上可以工作,但将光标绘制到位图时就会出现问题。 非常感谢任何建议。