/// <summary> /// Calculate an acceptable position of the DropDownForm even in a /// multi screen environment. /// </summary> /// <param name="DropDown"></param> /// <returns></returns> private Point GetDropDownPosition(DropDownForm DropDown) { Point lt = Parent.PointToScreen(new Point(Left, Top)); Point rb = Parent.PointToScreen(new Point(Right, Bottom)); Rectangle screen = Screen.FromControl(this).Bounds; Point point = new Point(); if (((lt.X + DropDown.Width) > (screen.X + screen.Width)) && ((rb.X - DropDown.Width) >= screen.X)) { point.X = rb.X - DropDown.Width; if ((point.X + DropDown.Width) > (screen.X + screen.Width)) { point.X = ((screen.X + screen.Width) - DropDown.Width); } } else { point.X = lt.X; if (point.X < screen.X) { point.X = screen.X; } } if (((rb.Y + DropDown.Height) > (screen.Y + screen.Height)) && ((lt.Y - DropDown.Height) >= screen.Y)) { point.Y = lt.Y - DropDown.Height; if (point.Y < screen.Y) { point.Y = screen.Y; } } else { point.Y = rb.Y; if ((point.Y + DropDown.Height) > (screen.Y + screen.Height)) { point.Y = ((screen.Y + screen.Height) - DropDown.Height); } } return(point); }
/// <summary> /// We make our DropDownForm host the choosen control and show it instead /// of the dropdown portion of the ComboBox. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Combo_DropDown(object sender, EventArgs e) { if (!_dropDownHelper.DropDownShowing) { DropDownForm dropDown = new DropDownForm(_dropDownControl); dropDown.FinishEditing += new DropDownValueChangedEventHandler(DropDown_FinishEditing); dropDown.ValueChanged += new DropDownValueChangedEventHandler(DropDown_ValueChanged); combo.DroppedDown = false; _dropDownHelper.ShowDropDown(_owner, dropDown, GetDropDownPosition(dropDown)); } else { _dropDownHelper.CloseDropDown(); this.Focus(); } }