滚动条的问题

具体实现:当出现滚动条时,定位到中心位置     

const int EM_LINESCROLL = 0x00B6;
        [DllImport("user32.dll")]
        static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);
        [DllImport("user32.dll")]
        static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
        [DllImport("user32.dll")]
        static extern int GetScrollPos(IntPtr hwnd, int nbar);
        [DllImport("user32", CharSet = CharSet.Auto)]
        private static extern bool PostMessage(IntPtr hWnd, int nBar, int wParam, int lParam);
        [DllImport("user32", CharSet = CharSet.Auto)]
        private static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos, out int lpMaxPos);
        [DllImport("user32.dll")]
        static extern bool SetScrollRange (IntPtr hwnd, int iBar, int iMin,int  iMax,bool bRedraw) ;
   //  [DllImport("user32.dll")]
   //static extern bool GetScrollRange(IntPtr hwnd,int ibar,out int X ,out int y);
private const int SB_HORZ = 0x0;
private const int SB_VERT = 0x1;
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
private const int SB_THUMBPOSITION = 4;

 

 public int HScrollPos
        {
            get { return GetScrollPos((IntPtr)this.scrollpanel.Handle, SB_HORZ); }
            set { SetScrollPos((IntPtr)this.scrollpanel.Handle, SB_HORZ, value, true); }
        }

        /// <summary>
        /// Gets and Sets the Vertical Scroll position of the control.
        /// </summary>
        public int VScrollPos
        {
            get { return GetScrollPos((IntPtr)this.scrollpanel.Handle, SB_VERT); }
            set { SetScrollPos((IntPtr)this.scrollpanel.Handle, SB_VERT, value, false); }
        }

 

 

private void 放大_Click_1(object sender, EventArgs e)
        {

            btnSmaller.Enabled = true;
            int CtlWidth = axPhRemoteCtrl.Size.Width;
            int CtlHeight = axPhRemoteCtrl.Size.Height;
            int HeightConstX = CtlWidth / 10, HeightConstY = CtlHeight / 10;
            int CenterPointX = CtlWidth / 20, CenterPointY = CtlHeight / 20;
           

            this.axPhRemoteCtrl.Dock = DockStyle.None;
            this.axPhRemoteCtrl.Size = new Size(CtlWidth + HeightConstX, CtlHeight + HeightConstY);

            VScrollPos += CenterPointY;
            SendMessage(this.scrollpanel.Handle, WM_VSCROLL, SB_THUMBPOSITION + 0x10000 * CenterPointY, 0);
            HScrollPos += CenterPointX;
            SendMessage(this.scrollpanel.Handle, WM_HSCROLL, SB_THUMBPOSITION + 0x10000 * CenterPointX, 0);

            this.scrollpanel.Invalidate();
        }
 private void 缩小_Click(object sender, EventArgs e)
        {
            GetScrollRange(this.scrollpanel.Handle, SB_HORZ, out hx, out hy);
            GetScrollRange(this.scrollpanel.Handle, SB_VERT, out vx, out vy);
            MessageBox.Show(hx+ " "+ hy + " "+vx + " "+ vy );
            this.btnLarger.Enabled = true;
            int CtlWidth = axPhRemoteCtrl.Size.Width;
            int CtlHeight = axPhRemoteCtrl.Size.Height;
            int HeightConstX = -CtlWidth / 10, HeightConstY = -CtlHeight / 10;
            int CenterPointX = -CtlWidth / 20, CenterPointY = -CtlHeight / 20;
            if (this.scrollpanel.Width >= (CtlWidth + 2*HeightConstX) || scrollpanel.Height >= (CtlHeight + 2*HeightConstY))
            {
                //MessageBox.Show(this.scrollpanel.Width + " >= " + (CtlWidth + HeightConstX) + "||" + scrollpanel.Height + ">=" + (CtlHeight + HeightConstY));
                this.axPhRemoteCtrl.Dock = DockStyle.Fill;
                this.btnSmaller.Enabled = false;
                return;
            }

            this.axPhRemoteCtrl.Dock = DockStyle.None;
            this.axPhRemoteCtrl.Size = new Size(CtlWidth + HeightConstX, CtlHeight + HeightConstY);
            VScrollPos += CenterPointY;
            SendMessage(this.scrollpanel.Handle, WM_VSCROLL, SB_THUMBPOSITION + 0x10000 * CenterPointY, 0);
            HScrollPos += CenterPointX;
            SendMessage(this.scrollpanel.Handle, WM_HSCROLL, SB_THUMBPOSITION + 0x10000 * CenterPointX, 0);

            this.scrollpanel.Invalidate();
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值