private void CalcMetrics(RadioGroupTemplate template) { _itemsRect = this.LocalRect; if (HasFrame) { _itemsRect = _itemsRect.Inflate(-1, -1); } int delta = _itemsRect.Size.Height - _items.Count; _numberItemsDisplayed = _items.Count; if (delta < 0) { _numberItemsDisplayed += delta; } if (RadioOnLeft) { _radioRect = new Rectangle(_itemsRect.TopLeft, new Size(1, 1)); _labelRect = new Rectangle(_radioRect.TopRight.Shift(1, 0), _itemsRect.TopRight.Shift(-1, 0)); } else { _radioRect = new Rectangle(_itemsRect.TopRight.Shift(-1, 0), new Size(1, 1)); _labelRect = new Rectangle(_itemsRect.TopLeft, _radioRect.BottomLeft.Shift(-2, -1)); } }
/// <summary> /// Construct a RadioGroup from the specified templated. /// </summary> /// <param name="template"></param> public RadioGroup(RadioGroupTemplate template) : base(template) { HasFrame = template.HasFrameBorder; if (Size.Width < 3 || Size.Height < 3) { HasFrame = false; } HilightWhenMouseOver = false; HilightRadioMouseOver = template.HilightRadioMouseOver; CanHaveKeyboardFocus = template.CanHaveKeyboardFocus; LabelAlignment = template.LabelAlignment; _items = template.Items; _mouseOverIndex = -1; RadioOnLeft = template.RadioOnLeft; Title = template.Title; CurrentSelected = template.InitialSelectedIndex; if (CurrentSelected < 0 || CurrentSelected >= _items.Count) { CurrentSelected = 0; } CalcMetrics(template); }