【发布时间】:2019-01-12 14:49:06
【问题描述】:
LinkLabel控件有一些烦人的问题:
- 默认情况下,它不使用任何系统颜色(即
Color.Blue而不是SystemColors.HotTrack用于LinkColor属性) - 它使用旧的、丑陋的、带有别名的手形光标版本
我找到了以下答案here,它声称可以解决光标问题:
using System.Runtime.InteropServices;
namespace System.Windows.Forms {
public class LinkLabelEx : LinkLabel {
private const int IDC_HAND = 32649;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
private static readonly Cursor SystemHandCursor = new Cursor(LoadCursor(IntPtr.Zero, IDC_HAND));
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
// If the base class decided to show the ugly hand cursor
if(OverrideCursor == Cursors.Hand) {
// Show the system hand cursor instead
OverrideCursor = SystemHandCursor;
}
}
}
}
但是,这个解决方案并不完美。例如,旧的、丑陋的光标在将鼠标悬停在正确的光标上之前会闪烁一帧。
我还阅读了ComCtl32.dll 中没有问题的原生SysLink 控件,但我找不到在C#/WinForms 中使用它的好解决方案。不过我还是更喜欢纯 .NET 解决方案。
如何通过解决上述问题使LinkLabel控件更好?
【问题讨论】:
-
问题是什么?创建
SysLink控件还是修复光标问题? -
@RezaAghaei 我只提到了
SysLink,因为它没有提到的问题。但是,如果有纯 .NET 解决方案,我会更喜欢。 -
如果您将代码添加到您的问题中并清楚提到的问题您正在尝试解决的问题,IMO 它可以被视为一个好问题并且可能会重新打开。跨度>
-
@RezaAghaei 我现在重新表述了我的问题,以便更清楚我的意思。
-
@Reza Aghaei 重新打开。我认为您应该在此处发布答案,因为问题和上下文不同。
标签: c# .net winforms linklabel