Beispiel #1
0
        /// <summary>
        /// Overrided to controll del scrolling of the customControl VScrollBar1
        /// </summary>
        /// <param name="m"></param>
        /// <remarks></remarks>
        protected override void WndProc(ref Message m)
        {
            if (!this.DesignMode && !(!this.Parent.CanFocus | (_win == null)))
            {
                int  wndStyle  = Win32.GetWindowLong(this._win.Handle, Win32.GWL_STYLE);
                bool hsVisible = (wndStyle & Win32.WS_HSCROLL) != 0;
                bool vsVisible = (wndStyle & Win32.WS_VSCROLL) != 0;

                //debug
                //Console.WriteLine("Visible ScrollBars: " + GetVisibleScrollbars(_win));
                //ShowScrollBar(this._win.Handle, (int)ScrollBarDirection.SB_HORZ, false /*false*/);


                //vertical
                if (true)// (vsVisible || hsVisible)
                {
                    int  iWParam = (int)m.WParam;
                    int  iLParam = (int)m.LParam;
                    uint sbCode  = Win32.LoWord(m.WParam);

                    if (sbCode == Win32.SB_THUMBTRACK || sbCode == Win32.SB_THUMBPOSITION)
                    {
                        Win32.ScrollInfo siv = new Win32.ScrollInfo();
                        siv.cbSize = Marshal.SizeOf(siv);
                        siv.fMask  = (int)Win32.ScrollInfoMask.SIF_ALL;
                        Win32.ScrollInfo sih = siv;

                        uint nPos = Win32.HiWord(m.WParam);


                        Win32.GetScrollInfo(this._win.Handle, (int)Win32.ScrollBarDirection.SB_VERT, ref siv);
                        Win32.GetScrollInfo(this._win.Handle, (int)Win32.ScrollBarDirection.SB_HORZ, ref sih);

                        if ((sih.nMax + 0) <= sih.nPage)
                        {
                            this.HScrollBar1.Visible = false;
                        }
                        else
                        {
                            this.HScrollBar1.Visible = true;
                            if (sih.nPage != 0)
                            {
                                this.HScrollBar1.Maximum     = (sih.nMax - sih.nPage) + 1;
                                this.HScrollBar1.Minimum     = sih.nMin;
                                this.HScrollBar1.Value       = sih.nPos;
                                this.HScrollBar1.LargeChange = (int)Math.Round((double)(((double)sih.nMax) / ((double)sih.nPage)));
                                this.HScrollBar1.SyncThumbPositionWithLogicalValue();
                            }
                        }

                        if (vsVisible)
                        {
                            if ((siv.nMax + 0) < siv.nPage)
                            {
                                this.VScrollBar1.Visible = false;
                            }
                            else
                            {
                                this.VScrollBar1.Visible = true;
                                if (siv.nPage != 0)
                                {
                                    this.VScrollBar1.Maximum     = (siv.nMax - siv.nPage) + 1;
                                    this.VScrollBar1.Minimum     = siv.nMin;
                                    this.VScrollBar1.Value       = siv.nPos;
                                    this.VScrollBar1.LargeChange = (int)Math.Round((double)(((double)siv.nMax) / ((double)siv.nPage)));
                                    this.VScrollBar1.SyncThumbPositionWithLogicalValue();
                                }
                            }
                        }
                    }
                }
            }
            base.WndProc(ref m);
        }