2

我想将光标更改为黑色。我搜索了许多网站并最终得到了一些答案,但它们不适用于axShockwaveFlash. 我有这个:

Cursor = new Cursor(@"PathToCurFile");

它只更改表单的光标,但我想更改控件的鼠标。我尝试了另一种选择:

Cursor.Override = Cursor;

我相信它没有任何作用。所以我尝试了这个:

axShockwaveFlash1.Cursor = new Cursor(@"PathToCurFile");

同样,它什么也不做。有人能告诉我如何更改光标的颜色吗?

Edit1:我尝试在其上放置一个不可见的标签...确实更改了鼠标但我无法点击游戏,所以我尝试将点击传递给 AxShockwaveFalsh 我可以点击等但光标恢复正常。

4

1 回答 1

1

您将需要使用 Win32 API 在较低级别执行此操作。这是代码:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

using System.Runtime.InteropServices;
public class Form1
{
    [DllImport("user32.dll")]
    public static extern IntPtr SetCursor(IntPtr hCursor);

    [DllImport("user32.dll")]
    private static extern IntPtr LoadCursorFromFile(string lpFileName);

    [DllImport("user32.dll")]
    private static extern bool SetSystemCursor(IntPtr hCursor, int id);

    private const uint OCR_NORMAL = 32512;

    static Cursor ColoredCursor;

    public Form1()
    {
        this.Load += Form1_Load;
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        this.CenterToScreen();
    }

    private void Button1_Click(object sender, EventArgs e)
    {
        IntPtr cursor = LoadCursorFromFile("C:\\Whatever\\Whatever\\example.cur");
        bool ret_val = SetSystemCursor(cursor, OCR_NORMAL);
    }
}

我建议更改 axShockwaveFlash1 控件 MouseEnter 和 MouseLeave 事件中的光标,例如:

this.Controls["AxShockwaveFlashObject1"].MouseEnter +=Form1_MouseEnter;

如果没有这些事件,请将 axShockwaveFlash1 控件放在 PictureBox 控件中并使用其输入/输出鼠标事件。

于 2017-09-06T01:27:12.047 回答