/// <summary> /// Construct a CheckBox instance from the given template. /// </summary> /// <param name="template"></param> public CheckBox(CheckBoxTemplate template) : base(template) { HasFrame = template.HasFrameBorder; if (Size.Height < 3 || Size.Width < 3) { HasFrame = false; } HilightWhenMouseOver = template.HilightWhenMouseOver; CanHaveKeyboardFocus = template.CanHaveKeyboardFocus; this.Label = template.Label; if (Label == null) { Label = ""; } this.CheckOnLeft = template.CheckOnLeft; this.LabelAlignment = template.LabelAlignment; this.VerticalAlign = template.VerticalAlign; CalcMetrics(template); }
private void CalcMetrics(CheckBoxTemplate template) { Rectangle inner = this.LocalRect; if (template.HasFrameBorder && template.CalculateSize().Height >= 3) { inner = inner.Inflate(-1, -1); } int checkX; if (CheckOnLeft) { checkX = inner.Left; _labelRect = new Rectangle(inner.TopLeft.Shift(1, 0), inner.BottomRight.Shift(-1, -1)); } else { checkX = inner.Right - 1; _labelRect = new Rectangle(inner.TopLeft, inner.BottomRight.Shift(-2, -1)); } if (_labelRect.Size.Width < 1) { Label = ""; } switch (VerticalAlign) { case VerticalAlignment.Bottom: _checkPos = new Point(checkX, _labelRect.Bottom - 1); break; case VerticalAlignment.Center: _checkPos = new Point(checkX, _labelRect.Center.Y); break; case VerticalAlignment.Top: _checkPos = new Point(checkX, _labelRect.Top); break; } }