//当panel增加或删减控件时自动调用 private void RelaControlAddedOrRemoved(object sender, ControlEventArgs e) { Control con = (Control)sender; AdjustVScrollBar(); vScrollBar.BringToFront(); }
/// <summary> /// Recalculate the position of the vertical scrollbar /// </summary> protected virtual void RecalcVScrollBar() { if (verticalScroll != null) { int l_HeightHScroll = 0; if (horizontalScroll != null) { l_HeightHScroll = horizontalScroll.Height; } verticalScroll.Location = new Point(ClientRectangle.Width - verticalScroll.Width, 0); verticalScroll.Height = ClientRectangle.Height - l_HeightHScroll; verticalScroll.Minimum = 0; verticalScroll.Maximum = customScrollArea.Height > 0 ? customScrollArea.Height : 0; verticalScroll.LargeChange = Math.Max(5, ClientRectangle.Height - l_HeightHScroll); verticalScroll.SmallChange = verticalScroll.LargeChange / 5; if (verticalScroll.Value > MaximumVScroll) { verticalScroll.Value = MaximumVScroll; } verticalScroll.BringToFront(); } }
/// <summary> /// Recalculate the position of the vertical scrollbar /// </summary> protected virtual void RecalcVScrollBar() { if (m_VScroll != null) { int l_HeightHScroll = 0; if (m_HScroll != null) { l_HeightHScroll = m_HScroll.Height; } m_VScroll.Location = new Point(ClientRectangle.Width - m_VScroll.Width, 0); m_VScroll.Height = ClientRectangle.Height - l_HeightHScroll; m_VScroll.Minimum = 0; m_VScroll.Maximum = Math.Max(0, m_CustomScrollArea.Height); //Math.Max(0,m_CustomScrollArea.Height - ClientRectangle.Height) + m_HScroll.Height; m_VScroll.LargeChange = Math.Max(5, ClientRectangle.Height - l_HeightHScroll); m_VScroll.SmallChange = m_VScroll.LargeChange / 5; if (m_VScroll.Value > MaximumVScroll) { m_VScroll.Value = MaximumVScroll; } m_VScroll.BringToFront(); } }
public Select(Control _par, int _height = -1) { _height = _height < 0 ? Style.SelectBoxHeight : _height; this.Size = new Size(_par.ClientRectangle.Width, _height); this.MaximumSize = new Size(_par.ClientRectangle.Width - Style.PaddingSize * 2, _height); this.BackColor = Style.Colors.Light; this.ForeColor = Style.Colors.Text; this.BorderStyle = BorderStyle.None; this.Font = new Font(Style.Fonts.UI, Style.UITextSize); this.DoubleBuffered = true; this.Selected += new Action <int>(SelectEH); this.cont = new SelectBox(); this.cont.Size = this.Size.Shrink(Style.PaddingSize * 2); this.cont.BackColor = this.BackColor; this.cont.Location = new Point(Style.PaddingSize, Style.PaddingSize); this.Controls.Add(cont); VScrollBar v = new VScrollBar(); v.Dock = DockStyle.Right; v.Scroll += (s, e) => this.cont.VerticalScroll.Value = v.Value; this.Controls.Add(v); v.BringToFront(); MouseEventHandler scroll = new MouseEventHandler((s, e) => { if (v.Value - e.Delta / Settings.S.ScrollWheelDecelerator <= 1) { v.Value = 1; } else if (v.Value - e.Delta / Settings.S.ScrollWheelDecelerator >= v.Maximum - 1) { v.Value = v.Maximum - 1; } else { v.Value -= (int)((long)e.Delta / (long)Settings.S.ScrollWheelDecelerator); } if (this.cont.VerticalScroll.Value != v.Value) { this.cont.VerticalScroll.Value = v.Value; } }); this.cont.MouseWheel += scroll; this.MouseWheel += scroll; }
public ScrollPanel() : base() { FakeScroll = new VScrollBar(); this.Controls.Add(FakeScroll); FakeScroll.Dock = DockStyle.Right; FakeScroll.Enabled = false; FakeScroll.BringToFront(); this.AutoScroll = true; FakeScroll.Visible = !VerticalScroll.Visible; STimer = new System.Timers.Timer(); STimer.Interval = 50; STimer.Elapsed += Tick; STimer.Start(); }
private void DoResize() { #if REPMAN_COMPACT if (Parent == null) { return; } if ((HBar == null) && (FAutoScale != AutoScaleType.EntirePage)) { HBar = new System.Windows.Forms.HScrollBar(); VBar = new System.Windows.Forms.VScrollBar(); HBar.Top = Height - HBar.Height; HBar.Left = 0; HBar.Width = Width; VBar.Left = Width - VBar.Width; VBar.Top = 0; VBar.Height = Height - HBar.Height; FBarWidth = VBar.Width; FBarHeight = HBar.Height; HBar.Parent = this; VBar.Parent = this; HBar.BringToFront(); VBar.BringToFront(); HBar.ValueChanged += new EventHandler(DoHBarChange); VBar.ValueChanged += new EventHandler(DoVBarChange); HBar.Maximum = image.Width - (Width - VBar.Width); VBar.Maximum = image.Height - (Height - HBar.Height); HBar.Minimum = 0; VBar.Minimum = 0; } #else int hoffset = FBarWidth; int voffset = FBarHeight; if (!HScroll) { voffset = 0; } if (!VScroll) { hoffset = 0; } int imLeft, imTop; imLeft = 0; imTop = 0; if (Parent == null) { return; } if (image.Width < Parent.ClientSize.Width - hoffset) { imLeft = (Parent.ClientSize.Width - image.Width - hoffset) / 2; } if (image.Height < Parent.ClientSize.Height - voffset) { imTop = (Parent.ClientSize.Height - image.Height - voffset) / 2; } int newleft = imLeft - Math.Abs(AutoScrollPosition.X); int newtop = imTop - Math.Abs(AutoScrollPosition.Y); if ((image.Left != newleft) || (image.Top != newtop)) { image.SetBounds(newleft, newtop, image.Width, image.Height); } #endif }