public static void Init(frmMain ins) { mainIns = ins; Init(new frmDescription(), () => { AttachedControl con = new AttachedControl(instance.webBrowser1); con[EventType.Loaded] = (sender, e) => { wasOpened = true; instance.webBrowser1.Navigate(Program.GetHugeFormUri(instance)); }; }); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the size and location of the drop-down control. /// </summary> /// <param name="width">Width of the drop-down control.</param> /// <param name="height">Height of the drop-down control.</param> /// ------------------------------------------------------------------------------------ private void SetSizeAndLocationOfPopupDropDown(int width, int height) { Size dropDownSize = new Size(width, height); if (AttachedControl == null && AttachedControl.Width < dropDownSize.Width) { Size = dropDownSize; return; } Point dropDownLocation = AttachedControl.PointToScreen(new Point(0, AttachedControl.Height)); // Get the working area (i.e. the screen's rectangle) in which the attached // control lies. Rectangle rcScreen = Screen.GetWorkingArea(AttachedControl); // Check if the right edge of the drop-down goes off the screen. If so, // align its right edge with that of the attached control's right edge. // The assumption is the right edge of the control isn't off the right // edge of the screen. If it is, tough luck, I guess. if (dropDownLocation.X + dropDownSize.Width > rcScreen.Right) { dropDownLocation.X -= (dropDownSize.Width - AttachedControl.Width); } // Check if the bottom edge of the drop-down goes off the screen. If so, // align its bottom edge with that of the attached control's top edge. if (dropDownLocation.Y + dropDownSize.Height > rcScreen.Bottom) { dropDownLocation.Y -= (dropDownSize.Height + AttachedControl.Height); } Size = dropDownSize; Location = dropDownLocation; }