vb的listview添加滚动条
VB中用listview的report格式的时候由于字段比较多,有14个。但是只能显示8个,剩下的都在最右边。下面也没有滚动条。。求教高手怎么给listview添加横向和...
VB中用listview的report格式的时候由于字段比较多,有14个。但是只能显示8个,剩下的都在最右边。下面也没有滚动条。。
求教高手怎么给listview添加横向和纵向的滚动条啊??
listview有这个属性吗?没找到啊
我设置了滚动条以平面显示怎么还是不行啊??
晕,“准VB专家”我要的是listview的滚动条,不是list的~~~
tanghailin26 朋友。我不是要隐藏列头,是要显示滚动条啊~~~ 展开
求教高手怎么给listview添加横向和纵向的滚动条啊??
listview有这个属性吗?没找到啊
我设置了滚动条以平面显示怎么还是不行啊??
晕,“准VB专家”我要的是listview的滚动条,不是list的~~~
tanghailin26 朋友。我不是要隐藏列头,是要显示滚动条啊~~~ 展开
4个回答
展开全部
以前有人问过这个问题,下面是答案:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
For i = 1 To 20
List1.AddItem String(100, "0") & i
Next
SendMessage List1.hwnd, &H194, 999, ByVal 0 '999是滚动条的宽度范围,单位为象素
End Sub
=============================================================
更优的代码
'计算出列表框内最长的项目有多少象素的宽度,这样可以使列表框的滚动条调整到一个合适的范围,因为列表框的内容很可能是会变动的,如果生硬的加一个很大的滚动条,同样会使你的程序显得很不专业,所以这一段是更优的代码!
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Const DT_CALCRECT = &H400
Public Function ListTextWidth(ByRef lstThis As ListBox) As Long
Dim i As Long
Dim tR As RECT
Dim lW As Long
Dim lWidth As Long
Dim lHDC As Long
With lstThis.Parent.Font
.Name = lstThis.Font.Name
.Size = lstThis.Font.Size
.Bold = lstThis.Font.Bold
.Italic = lstThis.Font.Italic
End With
lHDC = lstThis.Parent.hdc
'便历所有的列表项以找到最长的项
For i = 0 To lstThis.ListCount - 1
DrawText lHDC, lstThis.List(i), -1, tR, DT_CALCRECT
lW = tR.Right - tR.Left + 8
If (lW > lWidth) Then lWidth = lW
Next i
'返回最长列表项的长度(像素)
ListTextWidth = lWidth
End Function
'调用代码
Private Sub Command1_Click() '点击Command1会使列表框按当前内容中最长项目的宽度来设置滚动条的范围
'列表框内容有变化时,可以调用这行代码,随时改变滚动条的范围
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ListTextWidth(List1), 0
'写在这里是为了让你看清楚列表框滚动条的变化
End Sub
'测试数据
Private Sub Form_Load()
Command1.Caption = "点我"
For i = 1 To 100
'添加很长的项目给列表框
List1.AddItem String(i, "0")
Next
End Sub
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
For i = 1 To 20
List1.AddItem String(100, "0") & i
Next
SendMessage List1.hwnd, &H194, 999, ByVal 0 '999是滚动条的宽度范围,单位为象素
End Sub
=============================================================
更优的代码
'计算出列表框内最长的项目有多少象素的宽度,这样可以使列表框的滚动条调整到一个合适的范围,因为列表框的内容很可能是会变动的,如果生硬的加一个很大的滚动条,同样会使你的程序显得很不专业,所以这一段是更优的代码!
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Const DT_CALCRECT = &H400
Public Function ListTextWidth(ByRef lstThis As ListBox) As Long
Dim i As Long
Dim tR As RECT
Dim lW As Long
Dim lWidth As Long
Dim lHDC As Long
With lstThis.Parent.Font
.Name = lstThis.Font.Name
.Size = lstThis.Font.Size
.Bold = lstThis.Font.Bold
.Italic = lstThis.Font.Italic
End With
lHDC = lstThis.Parent.hdc
'便历所有的列表项以找到最长的项
For i = 0 To lstThis.ListCount - 1
DrawText lHDC, lstThis.List(i), -1, tR, DT_CALCRECT
lW = tR.Right - tR.Left + 8
If (lW > lWidth) Then lWidth = lW
Next i
'返回最长列表项的长度(像素)
ListTextWidth = lWidth
End Function
'调用代码
Private Sub Command1_Click() '点击Command1会使列表框按当前内容中最长项目的宽度来设置滚动条的范围
'列表框内容有变化时,可以调用这行代码,随时改变滚动条的范围
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, ListTextWidth(List1), 0
'写在这里是为了让你看清楚列表框滚动条的变化
End Sub
'测试数据
Private Sub Form_Load()
Command1.Caption = "点我"
For i = 1 To 100
'添加很长的项目给列表框
List1.AddItem String(i, "0")
Next
End Sub
展开全部
在listview点击右键--属性,将里面的的隐藏列头勾选上就有了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
‘LV为ListView控件
LV.View = lvwReport 显示方式
With LV
.ListItems.Clear
'.FullRowSelect = True
.ColumnHeaders.Clear '''列表的表头
.ColumnHeaders.Add , , "AAAAAAAA", 2000
.ColumnHeaders.Add , , "BBBBBBBB", 1000
.ColumnHeaders.Add , , "CCCCCCCC", 500
.ColumnHeaders.Add , , "DDDDDDDD", 2000
End With
没问题,下面就有滚动条。
LV.View = lvwReport 显示方式
With LV
.ListItems.Clear
'.FullRowSelect = True
.ColumnHeaders.Clear '''列表的表头
.ColumnHeaders.Add , , "AAAAAAAA", 2000
.ColumnHeaders.Add , , "BBBBBBBB", 1000
.ColumnHeaders.Add , , "CCCCCCCC", 500
.ColumnHeaders.Add , , "DDDDDDDD", 2000
End With
没问题,下面就有滚动条。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2018-07-29 · 专业短信验证码、公众号开发推广
杭州奥道网络技术有限公司
奥道网络以商业短信为起家的移动营销整体解决方案服务商,无论在产品性能、用户满意度还是体验友好度层面都得到客户的肯定,目前拥有自主知识产权及3项中国计算机软件著作权。
向TA提问
关注
展开全部
一般是自动添加滚动条,不过将属性flatscrollbar设置为true的时候好像不会自动出现滚动条
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询