public void ShowImageList(Item[] items) { HideImageList(); this.comboBox.Items.AddRange(items); using (Graphics g = CreateGraphics()) { DetermineMaxItemSize(g, items, out this.itemSize, out this.maxImageSize); } this.comboBox.ItemHeight = this.itemSize.Height; this.comboBox.DropDownWidth = this.itemSize.Width + SystemInformation.VerticalScrollBarWidth + UI.ScaleWidth(2); // Determine the max drop down height so that we don't cover up the button Screen ourScreen = Screen.FromControl(this); Point screenLocation = PointToScreen(new Point(this.comboBox.Left, this.comboBox.Bottom)); int comboBoxToFloorHeight = ourScreen.WorkingArea.Height - screenLocation.Y; // make sure it is an integral multiple of itemSize.Height comboBoxToFloorHeight = this.itemSize.Height * (comboBoxToFloorHeight / this.itemSize.Height); // add 2 pixels for border comboBoxToFloorHeight += 2; // But make sure it can hold at least 3 items int minDropDownHeight = 2 + itemSize.Height * 3; // +2 for combobox's border int dropDownHeight = Math.Max(comboBoxToFloorHeight, minDropDownHeight); this.comboBox.DropDownHeight = dropDownHeight; int selectedIndex = Array.FindIndex( items, delegate(Item item) { return(item.Selected); }); this.comboBox.SelectedIndex = selectedIndex; // Make sure the combobox does not spill past the right edge of the screen int left = PointToScreen(new Point(0, Height)).X; if (left + this.comboBox.DropDownWidth > ourScreen.WorkingArea.Right) { left = ourScreen.WorkingArea.Right - this.comboBox.DropDownWidth; } Point clientPt = PointToClient(new Point(left, screenLocation.Y)); SuspendLayout(); this.comboBox.Left = clientPt.X; ResumeLayout(false); // Set focus to it so it can get mouse wheel events, and then show it! this.comboBox.Focus(); UI.ShowComboBox(this.comboBox, true); }
public void HideImageList() { UI.ShowComboBox(this.comboBox, false); }