如何更改“概述”的项目在列表框中而不更改选择?

发布于 2024-10-11 05:31:49 字数 456 浏览 4 评论 0原文

如何更改列表框中“概述”的项目?请参阅以下屏幕截图以了解详情:

屏幕截图展示了我所说的“概述”项目相对于“选定”项目的含义

背景: 我想要一个正常工作的标准多选列表框。不幸的是,Windows 窗体列表框(带有 SelectionMode.MultiExtended)的功能并不完整。缺少的功能是它不允许您使用 Ctrl+箭头键和 Ctrl+空格键选择一组不相交的项目。 (在 Windows 资源管理器中尝试一下,看看它应该如何工作。)我正在尝试子类化 ListBox 并添加这个缺失的功能。为此,我打算在 OnKeyDown 受保护方法中响应 Ctrl+箭头键,但为了做到这一点,我需要能够在不更改所选项目集的情况下移动轮廓。我该怎么做?

How do you change which item is “outlined” in a ListBox? See the following screenshot for clarification:

Screenshot demonstrating what I mean by “outlined” item as opposed to “selected” item

Background: I want to have a standard multi-select listbox that works normally. Unfortunately, the Windows Forms ListBox (with SelectionMode.MultiExtended) is not fully functional. The missing functionality is that it doesn’t let you select a disjoint set of items by using Ctrl+Arrow keys and Ctrl+Space. (Try it in Windows Explorer to see how it’s supposed to work.) I am trying to subclass ListBox and add this missing functionality. To this end, I intend to respond to Ctrl+Arrow keys in the OnKeyDown protected method, but in order to do so, I need to be able to move the outline without changing the set of selected items. How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2024-10-18 05:31:49

您可以通过将 LB_SETCARETINDEX 消息发送到列表框来完成此操作:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam);

public const uint LB_SETCARETINDEX = 0x019E;
public const uint LB_GETCARETINDEX = 0x019F;

[...]

public int OutlineIndex
{
    get
    {
        return (int) WinAPI.SendMessage(Handle, WinAPI.LB_GETCARETINDEX, 0, 0);
    }
    set
    {
        if (value < 0 || value >= Items.Count)
            throw new ArgumentException("OutlineIndex cannot be negative or greater than the size of the collection.", "value");
        WinAPI.SendMessage(Handle, WinAPI.LB_SETCARETINDEX, (uint) value, 0);

    }
}

You can do this by sending the LB_SETCARETINDEX message to the list box:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam, uint lParam);

public const uint LB_SETCARETINDEX = 0x019E;
public const uint LB_GETCARETINDEX = 0x019F;

[...]

public int OutlineIndex
{
    get
    {
        return (int) WinAPI.SendMessage(Handle, WinAPI.LB_GETCARETINDEX, 0, 0);
    }
    set
    {
        if (value < 0 || value >= Items.Count)
            throw new ArgumentException("OutlineIndex cannot be negative or greater than the size of the collection.", "value");
        WinAPI.SendMessage(Handle, WinAPI.LB_SETCARETINDEX, (uint) value, 0);

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文