public int GetListboxWidth() { PropertyValue unitValue = _ownerPropertyEnum.Property.GetValue(PropertyUnitLook.UnitValue); string[] units = unitValue.GetDisplayedValues(); Graphics graphics = CreateGraphics(); int maxWidth = 0; foreach (string unit in units) { Size size = Win32Calls.GetTextExtent(graphics, unit, Font); if (size.Width > maxWidth) { maxWidth = size.Width; } } int buttonWidth = GetButtonWidth(graphics); int width = maxWidth + 2 * _ownerPropertyEnum.Property.ParentGrid.GlobalTextMargin + buttonWidth; graphics.Dispose(); if (width > ClientRectangle.Width - buttonWidth - 20) { width = ClientRectangle.Width - buttonWidth - 20; } if (width < buttonWidth) { width = buttonWidth; } return(width); }
protected void ProcessArrowKey(Keys key, bool rotate) { PropertyValue unitValue = _ownerPropertyEnum.Property.GetValue(PropertyUnitLook.UnitValue); object[] displayStrings = unitValue.GetDisplayedValues(); int index = -1; if (unitValue.HasMultipleValues) { if (key == Keys.Up) { index = displayStrings.Length - 1; } else if (key == Keys.Down) { index = 0; } } else { for (int i = 0; i < displayStrings.Length; i++) { if (ListText.Equals(displayStrings[i])) { if ((key == Keys.Up) && (i > 0)) { index = i - 1; } else if ((key == Keys.Up) && rotate) { index = displayStrings.Length - 1; } else if ((key == Keys.Down) && (i < displayStrings.Length - 1)) { index = i + 1; } else if ((key == Keys.Down) && rotate) { index = 0; } break; } } } if (index != -1) { ListText = displayStrings[index].ToString(); if (RealtimeChange) { CommitListChanges(); } } }
public void InitializeContent(PropertyEnumerator propEnum, string currentValue, object valueKey) { _ownerPropertyEnumerator = propEnum; int width = 0; _propValue = (valueKey == null ? propEnum.Property.Value : propEnum.Property.GetValue(valueKey)); Graphics graphics = CreateGraphics(); object[] displayedValues = _propValue.GetDisplayedValues(); foreach (object str in displayedValues) { Items.Add(str.ToString()); Size size = Win32Calls.GetTextExtent(graphics, str.ToString(), propEnum.Property.ParentGrid.Font); if (width < size.Width) { width = size.Width; } } Win32Calls.TEXTMETRIC tm = new Win32Calls.TEXTMETRIC(); Win32Calls.GetTextMetrics(graphics, propEnum.Property.ParentGrid.Font, ref tm); graphics.Dispose(); ItemHeight = tm.tmHeight + propEnum.Property.ParentGrid.PropertyVerticalMargin - 2; Height = Math.Max(ItemHeight, Math.Min(200, ItemHeight * displayedValues.Length)); int margin = propEnum.Property.ParentGrid.GlobalTextMargin; Width = width + 2 * margin; if (_propValue.ImageList != null) { Width += ItemHeight + margin; } DrawMode = DrawMode.OwnerDrawFixed; SelectedItem = currentValue; // SelectedItem = _propValue.DisplayString; }