c# – Windows窗体应用中的非抗锯齿手形光标!

栏目: C# · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/6016995/un-antialiased-hand-cursor-in-windows-forms-apps
好的,所以你知道在 Windows

Vista和Windows 7 MS中如何更改手形光标(当你将鼠标悬停在超链接上时显示的手形光标),并为它添加了更多细节,因此它的抗锯齿效果很好而且边缘平滑?

那么,为什么它不像Windows Forms应用程序那样?

我看着一个看起来像是由一个穴居人绘制的蹩脚的手形光标,有没有办法以编程方式告诉它显示实际安装在系统中的那个?我查看了Windows目录中的Cursors文件夹,旧的手形光标甚至都没有!那么为什么WinForms仍在使用旧版本呢?我怎样才能’升级’呢?

是的,WinForms控件仍然使用Windows 98/2000附带的旧式手形光标.它缺乏Aero游标附带的抗锯齿效果.这是因为.NET Framework包含自己的硬编码游标,而不是系统默认使用.我认为这是因为.NET的早期版本的目标是Windows 95之类的操作系统没有与这个光标捆绑在一起,但是没有完成考古学来证明它.

幸运的是,强迫它使用正确的一个很容易.您只需告诉操作系统您希望它使用默认手形光标,然后无论用户运行程序的Windows版本是什么,即使他们已将鼠标光标更改为默认值,也是正确的主题.

最简单的方法是对现有控件进行子类化,重写 WndProc function 以拦截 WM_SETCURSOR message ,并告诉它使用系统IDC_HAND游标.你只需要一点P / Invoke魔法.

以下代码是使用LinkLabel控件的外观示例:

public class LinkLabelEx : LinkLabel
{
    private const int WM_SETCURSOR = 0x0020;
    private const int IDC_HAND = 32649;

    [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    private static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);

    [DllImport("user32.dll", CharSet=CharSet.Auto)]
    private static extern IntPtr SetCursor(IntPtr hCursor);

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_SETCURSOR)
        {
            // Set the cursor to use the system hand cursor
            SetCursor(LoadCursor(IntPtr.Zero, IDC_HAND));

            // Indicate that the message has been handled
            m.Result = IntPtr.Zero;
            return;
        }

        base.WndProc(ref m);
    }
}

翻译自:https://stackoverflow.com/questions/6016995/un-antialiased-hand-cursor-in-windows-forms-apps


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Flexible Pattern Matching in Strings

Flexible Pattern Matching in Strings

Gonzalo Navarro、Mathieu Raffinot / Cambridge University Press / 2007-7-30 / USD 64.99

String matching problems range from the relatively simple task of searching a single text for a string of characters to searching a database for approximate occurrences of a complex pattern. Recent ye......一起来看看 《Flexible Pattern Matching in Strings》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具