日期:2014-05-19  浏览次数:21316 次

Winforms如何获取ListView水平滚动条的滚动区域总高度???
如题...
现在通过GetScrollPos获取了滚动条移动的相对位置...
也通过SystemInformation得到滚动条上下箭头的位图高度...
请问怎样才能知道滚动按钮已经到达了滚动区域最底部呢???

------解决方案--------------------
我也想知道...
------解决方案--------------------
替楼主顶一下!
我也想知道。呵呵
------解决方案--------------------
listView1.Items[listView1.Items.Count-1].EnsureVisible();//对你有用吗?
------解决方案--------------------
listView1.Items[listView1.Items.Count - 1].EnsureVisible();//对你有用吗?
//解释一下,这语句会把滚动条滚到最后,得到滚动条位置就得总高度啦.不过你得总高度干嘛,可能是显示最后一条吧?
------解决方案--------------------
获取水平滚动条的默认高度(以像素为单位)。
SystemInformation.HorizontalScrollBarHeight

------解决方案--------------------
关注...
------解决方案--------------------
在滚动条的Scroll事件中,我们可以通过它的事件参数来得到更多的信息,这个参数的类型是:
ScrollEventArgs

在这个类型中有如下类型的属性:
public ScrollEventType Type { get; }

因此我们可以在Scroll事件里通过如下的代码得到滚动条是否滚动到了最大值:

private void hScroll(object sender, ScrollEventArgs e)
{
if (e.Type == ScrollEventType.Last)
{
//到了最大的滚动值
}
}

但是在ListView中不能直接的得到这个事件,不过楼主有足够的时间来研究的话,可以在Listview中找到要处理的滚动条句柄,由系统函数可以通过这个句柄得到我们需要的信息.我只是这个想法,并没有实现的实现过.
------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication13
{
delegate void DelegeteScrollBottom(int newvalue,int oldvalue);
class MyListView : ListView
{
public MyListView()
{

}

/// <summary>
/// 水平滚动事件
/// </summary>
public event DelegeteScrollBottom Scroll;
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
private int OldVscrollValue = 0;

[DllImport( "user32 ")]
public static extern int GetScrollPos(IntPtr hWnd, int nBar);


protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_VSCROLL:

int NewVscrollValue = GetScrollPos(m.HWnd, 1);

if (Scroll != null)
{ Scroll(NewVscrollValue, OldVscrollValue); }

OldVscrollValue = NewVscrollValue;
base.WndProc(ref m);
break;

default:
base.WndProc(ref m);
break;
}
}
}
}

为ListView 写了个垂直滚事件,可以得到新值和旧值

/////////////////////////////////////////
自已已经解决的问题... <-----在事件中判断一下新值==你解决的高度就是到底啦.

再等待其他人的方案.明天结贴了...

请大家也发表一下吧...

///////////////////
LZ也发你怎么获取高度代码上来看看吧..交个朋友QQ5970356
------解决方案--------------------
^o^是按照你们思路写的~~谢谢可以给我看看~~~