C#工具提示:需要将光标可见性设置为false

时间:2013-06-06 03:10:05

标签: c# .net winforms

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

1 个答案:

答案 0 :(得分:2)

正如sa_ddam213所说:

只需使用Cursors.None Property

即可

或者您可以通过在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;
}