private void SetVMaxNum(Control control)
        {
            if (!m_lstVCache.ContainsKey(control))
            {
                return;
            }
            var          into  = ControlHelper.GetVScrollBarInfo(control.Handle);
            var          intoH = ControlHelper.GetHScrollBarInfo(control.Handle);
            UCVScrollbar barV  = m_lstVCache[control];

            if (control is ScrollableControl)
            {
                barV.Maximum = (control as ScrollableControl).VerticalScroll.Maximum;
                barV.Value   = (control as ScrollableControl).VerticalScroll.Value;
            }
            else if (control is TreeView)
            {
                barV.Maximum = GetTreeNodeMaxY(control as TreeView);
                barV.Value   = (control as TreeView).AutoScrollOffset.Y;
            }
            else if (control is TextBox)
            {
                TextBox txt             = (TextBox)control;
                int     intTxtMaxHeight = 0;
                int     intTextHeight   = 0;
                using (var g = txt.CreateGraphics())
                {
                    intTxtMaxHeight = (int)g.MeasureString(txt.Text, txt.Font).Height;
                    intTextHeight   = (int)g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font).Height;
                }
                barV.Maximum = intTxtMaxHeight;
                barV.Value   = (control as TextBox).AutoScrollOffset.Y;
            }
        }
Ejemplo n.º 2
0
        void barV_Scroll(object sender, EventArgs e)
        {
            UCVScrollbar bar = (UCVScrollbar)sender;

            if (m_lstVCache.ContainsValue(bar))
            {
                Control c = m_lstVCache.FirstOrDefault(p => p.Value == bar).Key;

                //ControlHelper.SetVScrollValue(c.Handle, bar.Value);
                if (c is ScrollableControl)
                {
                    (c as ScrollableControl).AutoScrollPosition = new Point((c as ScrollableControl).AutoScrollPosition.X, bar.Value);
                }
                else if (c is TreeView)
                {
                    ControlHelper.SetVScrollValue(c.Handle, bar.Value / ((c as TreeView).ItemHeight));
                }
                else if (c is TextBox)
                {
                    ControlHelper.SetVScrollValue(c.Handle, bar.Value / ((c as TextBox).PreferredHeight));
                }
                else if (c is RichTextBox)
                {
                    ControlHelper.SetVScrollValue(c.Handle, bar.Value);
                }
                else if (c is ListBox)
                {
                    ControlHelper.SetVScrollValue(c.Handle, bar.Value / ((c as ListBox).ItemHeight));
                }
                else if (c is ListView)
                {
                    ControlHelper.SetVScrollValue(c.Handle, bar.Value);
                }
                else if (c is DataGridView)
                {
                    var dgv = (DataGridView)c;
                    if (bar.Value > 0)
                    {
                        dgv.FirstDisplayedScrollingRowIndex = bar.Value - 1;
                    }
                }
            }
        }
        void barV_Scroll(object sender, EventArgs e)
        {
            UCVScrollbar bar = (UCVScrollbar)sender;

            if (m_lstVCache.ContainsValue(bar))
            {
                Control c = m_lstVCache.FirstOrDefault(p => p.Value == bar).Key;
                if (c is ScrollableControl)
                {
                    (c as ScrollableControl).AutoScrollPosition = new Point((c as ScrollableControl).AutoScrollPosition.X, bar.Value);
                }
                else if (c is TreeView)
                {
                    TreeView tv = (c as TreeView);
                    SetTreeViewVScrollLocation(tv, tv.Nodes, bar.Value);
                }
                else if (c is TextBox)
                {
                    TextBox txt = (c as TextBox);
                    SetTextBoxVScrollLocation(txt, bar.Value);
                }
            }
        }
        void control_SizeChanged(object sender, EventArgs e)
        {
            if (ControlHelper.IsDesignMode())
            {
                return;
            }
            else
            {
                var control = sender as Control;

                bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
                bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;
                if (blnHasVScrollbar)
                {
                    if (!m_lstVCache.ContainsKey(control))
                    {
                        if (control.Parent != null)
                        {
                            UCVScrollbar barV = new UCVScrollbar();
                            barV.Width = SystemInformation.VerticalScrollBarWidth;

                            barV.Scroll         += barV_Scroll;
                            m_lstVCache[control] = barV;
                            if (blnHasHScrollbar)
                            {
                                barV.Height = control.Height - barV.Width - 2;
                            }
                            else
                            {
                                barV.Height = control.Height - 2;
                            }
                            SetVMaxNum(control);
                            barV.Location = new System.Drawing.Point(control.Right - barV.Width - 1, control.Top + 1);
                            control.Parent.Controls.Add(barV);
                            int intControlIndex = control.Parent.Controls.GetChildIndex(control);
                            control.Parent.Controls.SetChildIndex(barV, intControlIndex);
                        }
                    }
                    else
                    {
                        SetVMaxNum(control);
                    }
                }
                else
                {
                    if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null)
                    {
                        m_lstVCache[control].Parent.Controls.Remove(m_lstVCache[control]);
                        m_lstVCache.Remove(control);
                    }
                }

                if (blnHasHScrollbar)
                {
                    if (!m_lstHCache.ContainsKey(control))
                    {
                        if (control.Parent != null)
                        {
                            UCHScrollbar barH = new UCHScrollbar();
                            barH.Height = SystemInformation.HorizontalScrollBarHeight;

                            barH.Scroll         += barH_Scroll;
                            m_lstHCache[control] = barH;
                            if (blnHasHScrollbar)
                            {
                                barH.Width = control.Width - barH.Height - 2;
                            }
                            else
                            {
                                barH.Width = control.Width - 2;
                            }
                            SetHMaxNum(control);
                            barH.Location = new System.Drawing.Point(control.Left + 1, control.Bottom - barH.Height - 1);
                            control.Parent.Controls.Add(barH);
                            int intControlIndex = control.Parent.Controls.GetChildIndex(control);
                            control.Parent.Controls.SetChildIndex(barH, intControlIndex);
                        }
                    }
                    else
                    {
                        SetHMaxNum(control);
                    }
                }
                else
                {
                    if (m_lstHCache.ContainsKey(control))
                    {
                        if (m_lstHCache[control].Visible)
                        {
                            m_lstHCache[control].Parent.Controls.Remove(m_lstHCache[control]);
                        }
                    }
                }
            }
            ResetScrollLocation(sender);
        }
Ejemplo n.º 5
0
        private void SetVMaxNum(Control control)
        {
            if (!m_lstVCache.ContainsKey(control))
            {
                return;
            }
            var          intoV = ControlHelper.GetVScrollBarInfo(control.Handle);
            UCVScrollbar barV  = m_lstVCache[control];

            if (control is ScrollableControl)
            {
                barV.Maximum = intoV.ScrollMax;
                barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
                barV.Value   = intoV.nPos;
                barV.BringToFront();
                // barV.Maximum = (control as ScrollableControl).VerticalScroll.Maximum;
                // barV.Value = (control as ScrollableControl).VerticalScroll.Value;
            }
            else if (control is TreeView)
            {
                var tv = control as TreeView;
                barV.Maximum = intoV.ScrollMax * tv.ItemHeight;
                barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
                barV.Value   = intoV.nPos * tv.ItemHeight;
                barV.BringToFront();

                //barV.Maximum = GetTreeNodeMaxY(control as TreeView) - control.Height;
                //barV.Value = (control as TreeView).AutoScrollOffset.Y;
            }
            else if (control is TextBox)
            {
                TextBox txt = (TextBox)control;
                barV.Maximum = intoV.ScrollMax * txt.PreferredHeight;
                if (txt.ScrollBars == ScrollBars.Both || txt.ScrollBars == ScrollBars.Vertical)
                {
                    barV.Visible = true;
                }
                else
                {
                    barV.Visible = false;
                }
                barV.Value = intoV.nPos * txt.PreferredHeight;
                barV.BringToFront();
            }
            else if (control is RichTextBox)
            {
                bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
                barV.Maximum = intoV.ScrollMax;
                barV.Visible = blnHasVScrollbar;
                barV.Value   = intoV.nPos;
                barV.BringToFront();
            }
            else if (control is ListBox)
            {
                var lb = control as ListBox;
                if (intoV.ScrollMax <= 1)
                {
                    var v = lb.ItemHeight * lb.Items.Count - lb.Height;
                    if (v > 0)
                    {
                        barV.Maximum = v;
                    }
                    else
                    {
                        barV.Maximum = intoV.ScrollMax * lb.ItemHeight;
                    }
                }
                else
                {
                    barV.Maximum = intoV.ScrollMax * lb.ItemHeight;
                }
                barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
                barV.Value   = intoV.nPos * lb.ItemHeight;
                barV.BringToFront();
            }
            else if (control is ListView)
            {
                barV.Maximum = intoV.ScrollMax;
                barV.Visible = intoV.ScrollMax > 0 && intoV.nMax > 0 && intoV.nPage > 0;
                barV.Value   = intoV.nPos;
                barV.BringToFront();
            }
            else if (control is DataGridView)
            {
                bool blnHasVScrollbar = false;
                var  dgv = (DataGridView)control;
                if (dgv.ScrollBars == ScrollBars.Both || dgv.ScrollBars == ScrollBars.Vertical)
                {
                    int _height = dgv.RowTemplate.Height * dgv.Rows.Count;
                    if (dgv.ColumnHeadersVisible)
                    {
                        _height += dgv.ColumnHeadersHeight;
                    }
                    blnHasVScrollbar = _height > dgv.Height;
                }
                barV.Maximum = dgv.Rows.Count;
                barV.Visible = blnHasVScrollbar;
                barV.Value   = dgv.FirstDisplayedScrollingRowIndex;;
                barV.BringToFront();
            }
        }
Ejemplo n.º 6
0
        void control_SizeChanged(object sender, EventArgs e)
        {
            if (ControlHelper.IsDesignMode())
            {
                return;
            }
            else
            {
                var control = sender as Control;

                bool blnHasVScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & VSCROLL) != 0;
                bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;
                if (control is TextBox)
                {
                    var txt = (TextBox)control;
                    if (txt.ScrollBars == ScrollBars.Both)
                    {
                        blnHasVScrollbar = true;
                        blnHasHScrollbar = true;
                    }
                    else if (txt.ScrollBars == ScrollBars.Vertical)
                    {
                        blnHasVScrollbar = true;
                        blnHasHScrollbar = false;
                    }
                    else if (txt.ScrollBars == ScrollBars.Horizontal)
                    {
                        blnHasVScrollbar = false;
                        blnHasHScrollbar = true;
                    }
                    else
                    {
                        blnHasVScrollbar = false;
                        blnHasHScrollbar = false;
                    }
                }
                else if (control is DataGridView)
                {
                    var dgv = (DataGridView)control;
                    if (dgv.ScrollBars == ScrollBars.Both || dgv.ScrollBars == ScrollBars.Vertical)
                    {
                        int _height = dgv.RowTemplate.Height * dgv.Rows.Count;
                        if (dgv.ColumnHeadersVisible)
                        {
                            _height += dgv.ColumnHeadersHeight;
                        }
                        blnHasVScrollbar = _height > dgv.Height;
                    }
                    if (dgv.ScrollBars == ScrollBars.Both || dgv.ScrollBars == ScrollBars.Horizontal)
                    {
                        int _width = 0;
                        foreach (DataGridViewColumn com in dgv.Columns)
                        {
                            _width += com.Width;
                        }
                        if (dgv.RowHeadersVisible)
                        {
                            _width += dgv.RowHeadersWidth;
                        }
                        blnHasHScrollbar = _width > dgv.Width;
                    }
                }
                else if (control is ListView)
                {
                    if (!((ListView)control).Scrollable)
                    {
                        blnHasVScrollbar = false;
                        blnHasHScrollbar = false;
                    }
                }
                if (blnHasVScrollbar)
                {
                    if (!m_lstVCache.ContainsKey(control))
                    {
                        if (control.Parent != null)
                        {
                            UCVScrollbar barV = new UCVScrollbar();
                            barV.SmallChange     = 5;
                            barV.Width           = SystemInformation.VerticalScrollBarWidth + 1;
                            barV.Scroll         += barV_Scroll;
                            m_lstVCache[control] = barV;
                            if (blnHasHScrollbar)
                            {
                                barV.Height = control.Height - barV.Width;
                            }
                            else
                            {
                                barV.Height = control.Height;
                            }
                            SetVMaxNum(control);
                            barV.Location = new System.Drawing.Point(control.Right - barV.Width, control.Top);
                            control.Parent.Controls.Add(barV);
                            int intControlIndex = control.Parent.Controls.GetChildIndex(control);
                            control.Parent.Controls.SetChildIndex(barV, intControlIndex);
                        }
                    }
                    else
                    {
                        if (blnHasHScrollbar)
                        {
                            m_lstVCache[control].Height = control.Height - m_lstVCache[control].Width;
                        }
                        else
                        {
                            m_lstVCache[control].Height = control.Height;
                        }
                        SetVMaxNum(control);
                    }
                }
                else
                {
                    if (m_lstVCache.ContainsKey(control) && m_lstVCache[control].Parent != null)
                    {
                        m_lstVCache[control].Visible = false;
                    }
                }

                if (blnHasHScrollbar)
                {
                    if (!m_lstHCache.ContainsKey(control))
                    {
                        if (control.Parent != null)
                        {
                            UCHScrollbar barH = new UCHScrollbar();
                            barH.Height      = SystemInformation.HorizontalScrollBarHeight + 1;
                            barH.SmallChange = 5;

                            barH.Scroll         += barH_Scroll;
                            m_lstHCache[control] = barH;
                            if (blnHasHScrollbar)
                            {
                                barH.Width = control.Width - barH.Height;
                            }
                            else
                            {
                                barH.Width = control.Width;
                            }
                            SetHMaxNum(control);
                            barH.Location = new System.Drawing.Point(control.Left, control.Bottom - barH.Height);
                            control.Parent.Controls.Add(barH);
                            int intControlIndex = control.Parent.Controls.GetChildIndex(control);
                            control.Parent.Controls.SetChildIndex(barH, intControlIndex);
                        }
                    }
                    else
                    {
                        if (blnHasHScrollbar)
                        {
                            m_lstHCache[control].Width = control.Width - m_lstHCache[control].Height;
                        }
                        else
                        {
                            m_lstHCache[control].Width = control.Width;
                        }
                        SetHMaxNum(control);
                    }
                }
                else
                {
                    if (m_lstHCache.ContainsKey(control))
                    {
                        if (m_lstHCache[control].Visible && m_lstHCache[control].Parent != null)
                        {
                            m_lstHCache[control].Visible = false;
                        }
                    }
                }
            }
            ResetScrollLocation(sender);
        }