listbox滚动条怎么设置(VBA listbox控件横向滚动条的问题!)

本文目录
- VBA listbox控件横向滚动条的问题!
- C# 如何控制ListBox滚动条的滚动
- 怎么改listbox里面默认的滚动条样式
- c# winform 设置listbox滚动条位置
- 如何在listbox中加水平滚动条
- listbox怎么才能显示滚动条
- vb中ListBox怎么加左右滚动条ScrollBar
- listbox内容如何自动滚动 c# 实现
VBA listbox控件横向滚动条的问题!
你把listbox1的每一列指定宽度,只要所有列的宽度大于listbox1的框的最大宽度就会显示横向滚动条。
方法1、直接在listbox1的属性:columnwidths输入数值,用英文逗号隔开。
方法2、直接在Private Sub UserForm_Initialize()时添加代码ListBox1.ColumnCount = n’’’’’N要指定数值,表示分为几列。
ListBox1.ColumnWidths = 100 & ";" & 50 & ";" & 100
PS、默认为-1,就是平均分配每列。
C# 如何控制ListBox滚动条的滚动
详细步骤:
1在项目中添加新项--用户控件,我们命名为CustomScrollbar.cs
2.准备几张图片添加进项目资源作为滚动条重绘时要用的背景,我用的图片如下:
uparrow.png资源名称为uparrow ,滚动条的上箭头ThumbBottom.png资源名称为ThumbBottom ,滚动条中间滑道的背景
ThumbMiddle.png资源名称为ThumbMiddle ,滚动条的中间的拖动块
downarrow.png资源名称为downarrow ,滚动条的下箭头
3.然后就是利用上面图片做背景重画滚动条背景了,直接给出CustomScrollbar.cs的代码:
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Diagnostics;
namespace Winamp
{
public partial class CustomScrollbar : UserControl
{
protected Color moChannelColor = Color.Empty;
protected Image moUpArrowImage = null;//上箭头
//protected Image moUpArrowImage_Over = null;
//protected Image moUpArrowImage_Down = null;
protected Image moDownArrowImage = null;//下箭头
//protected Image moDownArrowImage_Over = null;
//protected Image moDownArrowImage_Down = null;
protected Image moThumbArrowImage = null;
protected Image moThumbTopImage = null;
protected Image moThumbTopSpanImage = null;
protected Image moThumbBottomImage = null;
protected Image moThumbBottomSpanImage = null;
protected Image moThumbMiddleImage = null;
protected int moLargeChange = 10;
protected int moSmallChange = 1;
protected int moMinimum = 0;
protected int moMaximum = 100;
protected int moValue = 0;
private int nClickPoint;
protected int moThumbTop = 0;
protected bool moAutoSize = false;
private bool moThumbDown = false;
private bool moThumbDragging = false;
public new event EventHandler Scroll = null;
public event EventHandler ValueChanged = null;
private int GetThumbHeight()
{
int nTrackHeight = (this.Height - (UpArrowImage.Height + DownArrowImage.Height));
float fThumbHeight = ((float)LargeChange / (float)Maximum) * nTrackHeight;
int nThumbHeight = (int)fThumbHeight;
if (nThumbHeight 》 nTrackHeight)
{
nThumbHeight = nTrackHeight;
fThumbHeight = nTrackHeight;
}
if (nThumbHeight 《 56)
{
nThumbHeight = 56;
fThumbHeight = 56;
}
怎么改listbox里面默认的滚动条样式
Crollbar-Face-color:滚动条页面颜色设定;
Scrollbar-Highlight-Color:滚动条斜面和左面颜色设定;
Scrollbar-Shadow-Color:滚动条下斜面和右面颜色设定;
Scrollbar-3Dlight-Color:滚动条上边和左边的边沿颜色设定;
Scrollbar-Arrow-Color:滚动条两端箭头颜色设定;
Scrollbar-Track-Color:滚动条底版颜色设定;
Scrollbar-Darkshadow-Color:滚动条下边和右边的边沿颜色设定。
c# winform 设置listbox滚动条位置
当 SelectionMode 为 SelectionMode.NONE 时,不能调用 SelectionMode.SelectedIndex 的方法。
所以,把 SelectedMode 改为其它就可以了。
然后, ListBox1.SelectedIndex = ListBox1.Items.Count - 1 。
如果你是想失去焦点,那 ListBox1.ClearSelected() 就可以了。
如何在listbox中加水平滚动条
方案一 横向滚动条的属性依然要设定为true SendMessage (GetDlgItem (IDC_LSTPROFILE),LB_SETHORIZONTALEXTENT,100,0); 第一个参数是listbox的HWND,把你的控件id换上第二个参数就用这个第三个是个整数,代表像素数,可以是个变量,你自己试试看。第四个参数就写0就可以了。你可以去搜索一下 LB_SETHORIZONTALEXTENT 这个消息。也许会有帮助。 方案二SendMessage( listbox.Handle, LB_SETHORIZONTALEXTENT, xxx, 0 ); xxx 是滚动条的长度,像素单位!自己计算需要多长!
listbox怎么才能显示滚动条
在对话框的oninitdialog中对于listbox添加完项目后,调用下面的函数即可以了。
SetListboxHorz(m_yourlistbox);
int SetListboxHorz( CListBox &listbox )
{
CString Name;
CSize Size;
CDC * DeviceContent = 0;
long Width = 0;
long Count = 0;
Count = listbox.GetCount();
if ( Count )
{
DeviceContent = listbox.GetDC();
for ( long Index = 0; Index 《 Count; Index++ )
{
listbox.GetText( Index, Name );
Size = DeviceContent-》 GetTextExtent( Name );
if ( Size.cx 》 Width )
Width = Size.cx;
}
listbox.ReleaseDC( DeviceContent );
}
listbox.SetHorizontalExtent( Width );
return TRUE;
} 或者:CPaintDC dc(this);
CSize sz;
int max_width=0;
m_listbox.AddString( "xxxxx ");
sz=dc.GetTextExtent( "xxxxx ");
if(max_width 《sz.cx)
max_width=sz.cx;
m_listbox.SendMessage(LB_SETHORIZONTALEXTENT,max_width,0);
vb中ListBox怎么加左右滚动条ScrollBar
参考如下:
Private
Sub
Form_Load()
Dim
Information#,
Scrollbar#
For
Information
=
1
To
88
List1.AddItem
_
"横滚动条示范"
&
_
"横滚动条示范"
&
_
"横滚动条示范"
Next
Information
Information
=
SendMessageLong(List1.hwnd,
LB_SETHORIZONTALEXTENT,
2000,
0)
’2000:控制横滚动条的范围(建议值2000-3000)
Scrollbar
=
GetWindowLong(List1.hwnd,
GWL_STYLE)
Scrollbar
=
Scrollbar
Or
WS_HSCROLL
SetWindowLong
List1.hwnd,
GWL_STYLE,
Scrollbar
SetWindowPos
List1.hwnd,
_
0,
0,
0,
0,
0,
_
SWP_NOMOVE
Or
SWP_NOOWNERZORDER
Or
SWP_NOSIZE
Or
SWP_FRAMECHANGED
End
Sub
listbox内容如何自动滚动 c# 实现
C# ListBox 自动滚动到底部 方法:
在ListBox中添加一条记录(ListBox.Items.Add方法)后,滚动条会自动回到顶部。我们可能更希望它自动滚动到底部,简要介绍几种方法。
方法一:
this.listBox1.Items.Add("new line");
this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
this.listBox1.SelectedIndex = -1;
在添加记录后,先选择最后一条记录,滚动条会自动到底部,再取消选择。
缺点是需两次设置选中条目,中间可能会出现反色的动画,影响美观。
方法二:
this.listBox1.Items.Add("new line");
this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight);
通过计算ListBox显示的行数,设置TopIndex属性(ListBox中第一个可见项的索引)而达到目的。
方法二 plus:智能滚动
bool scroll = false;
if(this.listBox1.TopIndex == this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight))
scroll = true;
this.listBox1.Items.Add("new line");
if (scroll)
this.listBox1.TopIndex = this.listBox1.Items.Count - (int)(this.listBox1.Height / this.listBox1.ItemHeight);
在添加新记录前,先计算滚动条是否在底部,从而决定添加后是否自动滚动。
既可以在需要时实现自动滚动,又不会在频繁添加记录时干扰用户对滚动条的控制。

更多文章:
进制转换的8421法(十进制如何转换成8421码~~请说方法)
2026年5月11日 00:45
线程和进程的区别是什么 面试(linux进程和线程的区别 面试)
2026年1月20日 03:15
rabbitmq最新版本(rabbitmq3.8.2安装步骤及集群配置)
2025年11月21日 11:00
易语言源码打开停止工作(同样一个易语言源码,为什么在我的电脑上运行就卡死,在别人的电脑上运行是正常的)
2026年5月15日 01:30
powershell快捷键打开(windows10的控制面板在哪里找)
2026年8月7日 07:15
oracle数据库完整性(oracle添加记录的时候提示违反完整性约束,未找到父项关键字怎么解决)
2025年10月15日 22:30
java找不到工作想去送快递了(昌平北大青鸟分享学Java找不到工作的原因)
2026年8月6日 10:45
后台管理系统模板如何使用(开源网店iWeb Shop的模板管理后台怎么操作有什么值得注意的地方)
2025年10月30日 18:15
高级程序设计语言的主要功能(高级语言的控制结构主要包含什么)
2025年12月8日 19:00
mapreduce的优势(hadoop与传统的关系型数据库(如oracle)相比,有什么优势及劣势)
2026年2月12日 15:00
java交互界面怎么做(北大青鸟java培训:常见交互设计表现形式)
2026年3月23日 04:00
pull together(pull together是什么意思)
2026年1月6日 13:30
substantial变形单词(哪些英语单词可以表达 “重要的” 以及它们的区别)
2026年1月13日 17:00
floor和ceil函数(Math之ceil、floor、round区别)
2026年1月22日 22:30
汉化版eclipse(在汉化版eclipse中编写java程序,无法解析start是什么意思)
2025年8月6日 22:30
interesting怎么读英语(“interesting”怎么读)
2026年5月11日 15:45











