0

是否可以在工具提示可见时将光标可见性设置为 false,并在工具提示消失时再次设置为 true?

4

1 回答 1

2

正如 sa_ddam213 所说:

只需使用Cursors.None 属性


或者您可以通过在简单地显示正常光标之前ToolTip.Show()和之后设置透明光标图像来手动执行此操作:ToolTip.Hide()

CursorHandler.LoadCursor("ProjName.Resources.Invisible.cur");
ToolTip.Show();

...

ToolTip.Hide();
CursorHandler.LoadCursor("ProjName.Resources.Normal.cur");

这是 CursorHandler 代码(我从http://www.codeproject.com/Articles/36540/Adobe-Eyedropper-Control获得):

public class CursorHandler
{
 [DllImport("user32.dll")] 
 private static extern IntPtr LoadCursorFromFile(string fileName);

public static Cursor LoadCursor(string resourcePath)
{
    Cursor c = new Cursor(getCursorHandle(resourcePath));
    return c;
}    

private static IntPtr getCursorHandle(string resourcePath)
{
    //Load cursor from Manifest Resource to Stream 
    Stream streamFrom =
    Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
    Stream streamTo =
    File.Create(Environment.GetEnvironmentVariable("TEMP") + @"\~cur.tmp");
    BinaryReader br = new BinaryReader(streamFrom);
    BinaryWriter bw = new BinaryWriter(streamTo);
    //Write cursor to temporary file 
    bw.Write(br.ReadBytes((int)streamFrom.Length));
    bw.Flush();
    bw.Close();
    br.Close();
    bw = null;
    br = null;
    streamFrom.Close();
    streamTo.Close();
    streamFrom = null;
    streamTo = null;
    //Load handle of temporary cursor file 
    IntPtr hwdCursor = LoadCursorFromFile(
    Environment.GetEnvironmentVariable("TEMP") + @"\~cur.tmp");
    //Delete temporary cursor file 
    File.Delete(Environment.GetEnvironmentVariable("TEMP") + @"\~cur.tmp");
    return hwdCursor;
}
于 2013-06-06T04:18:55.417 回答