public void DropDownControl(Control ctl) { DropDownCtl = (ChooserDropDown)ctl; if (editor.CanCall) { DropDownCtl.ValueOpenForm += new ValueEventHandler(DropDownService_ValueOpenForm); } if (dropDownForm == null) { dropDownForm = new DropDownForm(this); } dropDownForm.TopMost = true; dropDownForm.Visible = false; dropDownForm.Component = DropDownCtl; Size size = new Size(editor.DropDownWidth, editor.DropDownHeight); Point location = new Point(editor.Left, editor.Bottom); if (editor.DropDownAlign == CtlChooser.DropDownAlignment.Right) { location.X = editor.Right - size.Width - 1; } // location in screen coordinate location = editor.Parent.PointToScreen(location); // check the form is in the screen working area Rectangle screenWorkingArea = Screen.FromControl(editor).WorkingArea; location.X = Math.Min(screenWorkingArea.Right - size.Width, Math.Max(screenWorkingArea.X, location.X)); if (size.Height + location.Y + editor.Height > screenWorkingArea.Bottom) { location.Y = location.Y - size.Height - editor.Height - 1; } dropDownForm.FormBorderStyle = FormBorderStyle.FixedSingle; dropDownForm.SetBounds(location.X, location.Y, size.Width, size.Height); dropDownForm.MinimumSize = size; dropDownForm.Size = size; dropDownForm.Visible = true; DropDownCtl.Focus(); DropDownCtl.ValueSelected -= new ValueEventHandler(ctl_ValueSelected); DropDownCtl.ValueSelected += new ValueEventHandler(ctl_ValueSelected); DropDownCtl.ValueEscaped -= new EventHandler(DropDownService_ValueEscaped); DropDownCtl.ValueEscaped += new EventHandler(DropDownService_ValueEscaped); //editor.SelectTextBox(); // wait for the end of the editing //while (dropDownForm.Visible) //{ // Application.DoEvents(); // MsgWaitForMultipleObjects(0, 0, true, 250, 255); //} // editing is done or aborted }
public DropDownCalendarService(CtlDate ctl) { editor = ctl; Calendar = new MonthCalendar(); dropDownForm = new DropDownForm(Calendar); Calendar.DateSelected += new DateRangeEventHandler(DropDownCtl_DateSelected); Calendar.KeyDown += new KeyEventHandler(DropDownCtl_KeyDown); dropDownForm.Deactivate += new EventHandler(dropDownForm_Deactivate); }