当前位置: 代码迷 >> C# >> ,ListView窗口重绘,滚动条无法显示最底部数据
  详细解决方案

,ListView窗口重绘,滚动条无法显示最底部数据

热度:34   发布时间:2016-05-05 03:01:29.0
求助,ListView窗口重绘,滚动条无法显示最底部数据
   我想扩展一个ListView,让底部边框变厚。重绘修改客户区大小,出现滚动条无法显示最下端数据的问题。

拦截Windwos消息:修改客户区大小代码:
        protected override void DefWndProc(ref Message m)
        {
//bottomHeight 底部边框厚度,为了数据明显多加了200
            base.DefWndProc(ref m);
            switch (m.Msg)
            {
                case (int)WinMsg.WM_NCPAINT:
                    PaintBottom();
                    break;
                case (int)WinMsg.WM_NCCALCSIZE:
                    if (m.LParam != IntPtr.Zero)
                    {
                        if (m.WParam.ToInt32() == 1)
                        {
                            NCCALCSIZE_PARAMS csp = (NCCALCSIZE_PARAMS)m.GetLParam(typeof(NCCALCSIZE_PARAMS));
                            if (csp.rgrc[0].bottom - csp.rgrc[0].top < bottomHeight + 200 || !_ShowBottom)
                            {
                                drawBottom = false;
                            }
                            else
                            {
                                drawBottom = true;
                                csp.rgrc[0].bottom -= (bottomHeight + 100);
                            }
                            Marshal.StructureToPtr(csp, m.LParam, true);
                            //Return zero to preserve client rectangle
                            m.Result = IntPtr.Zero;
                        }
                        info.Visible = drawBottom;
                    }
                    break;
            }

///加厚边框绘图
        private void PaintBottom()
        {
            loading.Location = new Point((ClientRectangle.Width - loading.Width) / 2, (ClientRectangle.Height - loading.Height) / 2);
            if (!drawBottom)
                return;
            IntPtr hdc = Win32API.GetWindowDC(this.Handle);
            if (hdc == null)
                return;
            using (Graphics g = Graphics.FromHdc(hdc))
            {
                int bottomPos = 2;
                if (Win32API.IsHorizontalScrollBarVisible(this)){
                    bottomPos += SystemInformation.HorizontalScrollBarHeight;
                }
                //info.Size = new Size(Width - 6, Height - ClientRectangle.Height - bottomPos - 4);
                //info.Location = new Point(Location.X + 2, Location.Y + ClientRectangle.Bottom + bottomPos+2);
                //initializeControl();
                using (Brush brush = new SolidBrush(BackColor))
                {
                    g.FillRectangle(brush, new Rectangle(0, ClientRectangle.Bottom + bottomPos, Width, Height - ClientRectangle.Height - bottomPos));
                }
                if (!Win32API.IsHorizontalScrollBarVisible(this)){
                    g.DrawLine(SystemPens.ControlDarkDark, 0, ClientRectangle.Bottom + bottomPos+1, Width, ClientRectangle.Bottom + bottomPos+1);
                }
            }
            Win32API.ReleaseDC(this.Handle, hdc);
        }

        }


出现问题是数据显示不完全,下面是2张截图


就是发现在计算滚动条的时候,显示区域的大小是修改之前的大小。如何解决这问题。通过win32的setscrollinfo重写设置滚动条也没效果。。求助求助

------解决思路----------------------
只是为了让底下留下一大片空白?
那么你完全可以把listview拉小一点,然后设置一下Anchor属性,让它四边距离永远不变
而不要设置dock=fill
------解决思路----------------------
即使要做重绘,也应该重绘没有文字显示的部分,而不是把文字给遮盖了
------解决思路----------------------
看起来就是listview下面加了一个panel?
------解决思路----------------------
引用:
Quote: 引用:

看起来就是listview下面加了一个panel?

正确。为想在下面的panel中加上分页按钮,整体控件实现分页功能

所以你应该把panel加在listview外面,而不是放到listview里面
------解决思路----------------------
其实类似这样的需求,你应该用SplitContainer来布局
它天然就是2个panel,你把listview放到上面的panel里,你的按钮放到下面的panel里,这样不就互相不遮挡了,而且还可以随时调整上下的大小
------解决思路----------------------
那就是跟你重绘有关了
如何重绘的,代码放出来看
既然涉及重绘,就不要老强调panel了
  相关解决方案