private void SetHMaxNum(Control control)
        {
            if (!m_lstHCache.ContainsKey(control))
            {
                return;
            }
            UCHScrollbar barH = m_lstHCache[control];

            if (control is ScrollableControl)
            {
                barH.Maximum = (control as ScrollableControl).HorizontalScroll.Maximum;
                barH.Value   = (control as ScrollableControl).HorizontalScroll.Value;
            }
            else if (control is TreeView)
            {
                barH.Maximum = GetTreeNodeMaxX(control as TreeView);
                barH.Value   = (control as TreeView).AutoScrollOffset.X;
            }
            else if (control is TextBox)
            {
                TextBox txt            = (TextBox)control;
                int     intTxtMaxWidth = 0;
                int     intTextWidth   = 0;
                using (var g = txt.CreateGraphics())
                {
                    intTxtMaxWidth = (int)g.MeasureString(txt.Text, txt.Font).Width;
                    intTextWidth   = (int)g.MeasureString(txt.Text.Substring(0, txt.SelectionStart), txt.Font).Width;
                }
                barH.Maximum = intTxtMaxWidth;
                barH.Value   = (control as TextBox).AutoScrollOffset.Y;
            }
        }
예제 #2
0
        void barH_Scroll(object sender, EventArgs e)
        {
            UCHScrollbar bar = (UCHScrollbar)sender;

            if (m_lstHCache.ContainsValue(bar))
            {
                Control c = m_lstHCache.FirstOrDefault(p => p.Value == bar).Key;
                if (c is ScrollableControl)
                {
                    (c as ScrollableControl).AutoScrollPosition = new Point(bar.Value, (c as ScrollableControl).AutoScrollPosition.Y);
                }
                else if (c is TreeView)
                {
                    ControlHelper.SetHScrollValue(c.Handle, bar.Value);
                    //TreeView tv = (c as TreeView);
                    //SetTreeViewVScrollLocation(tv, tv.Nodes, bar.Value);
                }
                else if (c is TextBox)
                {
                    ControlHelper.SetHScrollValue(c.Handle, bar.Value);
                    //TextBox txt = (c as TextBox);
                    //SetTextBoxVScrollLocation(txt, bar.Value);
                }
                else if (c is RichTextBox)
                {
                    ControlHelper.SetHScrollValue(c.Handle, bar.Value);
                }
                else if (c is ListBox)
                {
                    ControlHelper.SetHScrollValue(c.Handle, bar.Value);
                }
                else if (c is ListView)
                {
                    ControlHelper.SetHScrollValue(c.Handle, bar.Value);
                }
                else if (c is DataGridView)
                {
                    var dgv = (DataGridView)c;
                    dgv.HorizontalScrollingOffset = bar.Value;
                }
            }
        }
        void barH_Scroll(object sender, EventArgs e)
        {
            UCHScrollbar bar = (UCHScrollbar)sender;

            if (m_lstHCache.ContainsValue(bar))
            {
                Control c = m_lstHCache.FirstOrDefault(p => p.Value == bar).Key;
                if (c is ScrollableControl)
                {
                    (c as ScrollableControl).AutoScrollPosition = new Point(bar.Value, (c as ScrollableControl).AutoScrollPosition.Y);
                }
                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);
        }
예제 #5
0
        private void SetHMaxNum(Control control)
        {
            if (!m_lstHCache.ContainsKey(control))
            {
                return;
            }
            var          intoH = ControlHelper.GetHScrollBarInfo(control.Handle);
            UCHScrollbar barH  = m_lstHCache[control];

            if (control is ScrollableControl)
            {
                barH.Maximum = intoH.ScrollMax;
                barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
                barH.Value   = intoH.nPos;
                barH.BringToFront();

                //barH.Maximum = (control as ScrollableControl).HorizontalScroll.Maximum;
                //barH.Value = (control as ScrollableControl).HorizontalScroll.Value;
            }
            else if (control is TreeView)
            {
                var tv = control as TreeView;
                barH.Maximum = intoH.ScrollMax;
                barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
                barH.Value   = intoH.nPos;
                barH.BringToFront();
                //barH.Maximum = GetTreeNodeMaxX(control as TreeView);
                //barH.Value = (control as TreeView).AutoScrollOffset.X;
            }
            else if (control is TextBox)
            {
                TextBox txt = (TextBox)control;
                barH.Maximum = intoH.ScrollMax;

                if (txt.ScrollBars == ScrollBars.Both || txt.ScrollBars == ScrollBars.Horizontal)
                {
                    barH.Visible = true;
                }
                else
                {
                    barH.Visible = false;
                }

                barH.Value = intoH.nPos;
                barH.BringToFront();
            }
            else if (control is RichTextBox)
            {
                bool blnHasHScrollbar = control.IsHandleCreated && (ControlHelper.GetWindowLong(control.Handle, STYLE) & HSCROLL) != 0;

                barH.Maximum = intoH.ScrollMax;
                barH.Visible = blnHasHScrollbar;
                barH.Value   = intoH.nPos;
                barH.BringToFront();
            }
            else if (control is ListBox)
            {
                var lb = control as ListBox;
                barH.Maximum = intoH.ScrollMax * lb.ItemHeight;
                barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
                barH.Value   = intoH.nPos * lb.ItemHeight;
                barH.BringToFront();
            }
            else if (control is ListView)
            {
                barH.Maximum = intoH.ScrollMax;
                barH.Visible = intoH.ScrollMax > 0 && intoH.nMax > 0 && intoH.nPage > 0;
                barH.Value   = intoH.nPos;
                barH.BringToFront();
            }
            else if (control is DataGridView)
            {
                bool blnHasHScrollbar = false;
                var  dgv    = (DataGridView)control;
                int  _width = 0;
                if (dgv.ScrollBars == ScrollBars.Both || dgv.ScrollBars == ScrollBars.Horizontal)
                {
                    foreach (DataGridViewColumn com in dgv.Columns)
                    {
                        _width += com.Width;
                    }
                    if (dgv.RowHeadersVisible)
                    {
                        _width += dgv.RowHeadersWidth;
                    }
                    blnHasHScrollbar = _width > dgv.Width;
                }
                if (blnHasHScrollbar)
                {
                    barH.Maximum = _width - dgv.Width;
                }
                barH.Visible = blnHasHScrollbar;
                barH.Value   = dgv.FirstDisplayedScrollingColumnHiddenWidth;
                barH.BringToFront();
            }
        }
예제 #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);
        }