/// <summary> /// Performs layout of sub controls, such as element host, scroll bars etc.. /// </summary> protected virtual void LayoutSubControls() { int vw = m_VScrollBar.Width; int hh = m_HScrollBar.Height; m_VScrollBar.SetBounds(Width - vw - Padding.Right, Padding.Top, vw, Height - hh - Padding.Vertical); m_HScrollBar.SetBounds(Padding.Left, Height - hh - Padding.Bottom, Width - vw - Padding.Horizontal, hh); var newWidth = m_VScrollBar.Left - 1 - Padding.Left; var newHeight = m_HScrollBar.Top - 1 - Padding.Top; var needRebuild = newHeight != m_CellView.Height; m_CellView.SetBounds(Padding.Left, Padding.Top, newWidth, newHeight); if (needRebuild) { rebuildAllCells(); } }
// OnFormLoad() /// <summary> /// Control is resizing. As it turns out, it's easier to code this manually than /// to fight with anchors, docking and adding Panel controls until it all works. /// </summary> /// <param name="sender"> /// Event sender /// </param> /// <param name="e"> /// Event parameters /// </param> private void OnResize(object sender, EventArgs e) { // first determine the minimum width int MinWidth = lblBrightness.Width; MinWidth += lblSaturation.Width; MinWidth += SELECTED_COLOR_WIDTH; int MinScrollBar = SystemInformation.HorizontalScrollBarArrowWidth * 2 + SystemInformation.HorizontalScrollBarThumbWidth; MinWidth += MinScrollBar * 2; Rectangle rcArea = ClientRectangle; int MinHeight = rcArea.Height; bool bChange = false; if (MinWidth > rcArea.Width) { bChange = true; } else { MinWidth = rcArea.Width; } if (MinHeight < SELECTED_COLOR_HEIGHT) { MinHeight = SELECTED_COLOR_HEIGHT; bChange = true; } if (bChange) { // at this point resizing will shrink over the control area because the control // cannot get any smaller rcArea = new Rectangle( ClientRectangle.Left, ClientRectangle.Top, MinWidth, MinHeight); } // next calculate the selected color area m_rcSelColor = new Rectangle( rcArea.Right - SELECTED_COLOR_WIDTH - 1, rcArea.Top, SELECTED_COLOR_WIDTH, rcArea.Height - 1); // calculate the height of the hue bar area, which is everything left over after // the bottom scroll bars are drawn, with a 1 pixel buffer int HueBarHeight = (rcArea.Bottom - rcArea.Top) - SystemInformation.HorizontalScrollBarHeight - 1; if (HueBarHeight < 0) { HueBarHeight = 20; // control is not going to fit... } // the left and right buttons. we shrink them a bit vertically so that the arrows // indicating the selected hue stand out a bit more btnLeft.SetBounds( rcArea.Left, rcArea.Top + HUE_SELECT_ARROW_HEIGHT, ARROW_BUTTON_WIDTH, HueBarHeight - (2 * HUE_SELECT_ARROW_HEIGHT) + 1); btnRight.SetBounds( m_rcSelColor.Left - ARROW_BUTTON_WIDTH - 1, rcArea.Top + HUE_SELECT_ARROW_HEIGHT, ARROW_BUTTON_WIDTH, HueBarHeight - (2 * HUE_SELECT_ARROW_HEIGHT) + 1); // and the hue bar area m_rcHueBar = new Rectangle( btnLeft.Right, rcArea.Top, btnRight.Left - btnLeft.Right, HueBarHeight); // important calculation for matching a screen pixel to a hue amount m_HuePixelStep = 360.0f / m_rcHueBar.Width; // finally, position the controls int ScrollWidth = ((m_rcSelColor.Left - rcArea.Left) - lblBrightness.Width - lblSaturation.Width) / 2; if (ScrollWidth < MinScrollBar) { ScrollWidth = MinScrollBar; } int BottomHeight = rcArea.Bottom - m_rcHueBar.Bottom; lblBrightness.SetBounds( rcArea.Left, m_rcHueBar.Bottom + 1, lblBrightness.Width, BottomHeight, BoundsSpecified.All); wndScrollBrightness.SetBounds( lblBrightness.Right, m_rcHueBar.Bottom + 1, ScrollWidth, BottomHeight, BoundsSpecified.All); lblSaturation.SetBounds( wndScrollBrightness.Right, m_rcHueBar.Bottom + 1, lblSaturation.Width, BottomHeight, BoundsSpecified.All); wndScrollSaturation.SetBounds( lblSaturation.Right, m_rcHueBar.Bottom + 1, ScrollWidth, BottomHeight, BoundsSpecified.All); }