gpt4 book ai didi

c# - Winforms - 如何防止列表框项目选择

转载 作者:太空狗 更新时间:2023-10-29 20:59:28 26 4
gpt4 key购买 nike

在 WinForms 中,我偶尔会在列表框上运行一个循环来选择项目。

在那段时间里,我不希望用户使用鼠标或按键选择该列表框中的项目。

我查看了 MyListbox.enabled=false,但它使所有项目变灰。不想这样。

如何防止选择列表框中的项目?

最佳答案

我也想要一个只读列表框,最后,经过大量搜索,从http://ajeethtechnotes.blogspot.com/2009/02/readonly-listbox.html 找到了这个。 :

public class ReadOnlyListBox : ListBox
{
private bool _readOnly = false;
public bool ReadOnly
{
get { return _readOnly; }
set { _readOnly = value; }
}

protected override void DefWndProc(ref Message m)
{
// If ReadOnly is set to true, then block any messages
// to the selection area from the mouse or keyboard.
// Let all other messages pass through to the
// Windows default implementation of DefWndProc.
if (!_readOnly || ((m.Msg <= 0x0200 || m.Msg >= 0x020E)
&& (m.Msg <= 0x0100 || m.Msg >= 0x0109)
&& m.Msg != 0x2111
&& m.Msg != 0x87))
{
base.DefWndProc(ref m);
}
}
}

关于c# - Winforms - 如何防止列表框项目选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8197923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com