Hide vertical scroll bar in ListBox control(隐藏 ListBox 控件中的垂直滚动条)
问题描述
我正在开发一个需要 ListBox
控件的应用程序.不幸的是,当我在 ListBox
中添加太多项目时,会显示一个垂直滚动条.我可以做些什么来隐藏 ListBox
显示的垂直滚动条吗?我可以看到有一个隐藏水平滚动条的属性,但没有垂直滚动条的属性.
I'm developing an application that requires a ListBox
control. Unfortunately, when I add too many items in the ListBox
, a vertical scroll bar is shown. Is there something I can do to hide the vertical scroll bar shown by the ListBox
? I can see that there's a property to hide the horizontal scroll bar but there's no property for the vertical scroll bar.
推荐答案
问题解决了.我只是使用以下代码创建了一个模板类库的新项目
The problem was solved. I've simply created a new project of template a class library with the following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClassLibrary1
{
public class MyListBox : System.Windows.Forms.ListBox
{
private bool mShowScroll;
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
if (!mShowScroll)
cp.Style = cp.Style & ~0x200000;
return cp;
}
}
public bool ShowScrollbar
{
get { return mShowScroll; }
set
{
if (value != mShowScroll)
{
mShowScroll = value;
if (IsHandleCreated)
RecreateHandle();
}
}
}
}
}
然后,我构建了输出新类库的项目ClassLibrary1.dll
Then, I've built the project outputting a new class library ClassLibrary1.dll
在我的主项目中,我右键单击了 ToolBox
并选择了 Choose Items...
.点击 Browse... 并选择我最近创建的类库 (ClassLibrary1.dll) 并点击 Open 然后点击 OK.因此,我能够拥有不再有垂直滚动条的自定义 ListBox
.
On my main project, I've right-clicked the ToolBox
and selected Choose Items...
. Clicked on Browse... and selected the class library that I've recently created (ClassLibrary1.dll) and clicked on Open then on OK. Thus, I was able to have my custom ListBox
which has no vertical scroll bars anymore.
这篇关于隐藏 ListBox 控件中的垂直滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:隐藏 ListBox 控件中的垂直滚动条


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01