using System.Windows.Forms; using System.Drawing; using FastReport.Forms; namespace FastReport.Controls { /// /// Represents a popup form. /// /// /// Use this form if you want to show some controls in non-modal borderless form that /// behaves like other standard popup controls such as context menu. This form does not /// move a focus from the parent form. /// public class PopupWindow : BaseForm { private Form ownerForm; private PopupWindowHelper popupHelper; /// /// Shows the form. /// /// The control which location is used as a reference for pt parameter. /// The location relative to the ctl control. public void Show(Control ctl, Point pt) { Show(ctl.PointToScreen(pt)); } /// /// Shows the form. /// /// The control which location is used as a reference for x, y parameters. /// The x position relative to the ctl control. /// The y position relative to the ctl control. public void Show(Control ctl, int x, int y) { Show(ctl, new Point(x, y)); } /// /// Shows the form. /// /// The absolute screen location. public void Show(Point pt) { Rectangle area = Screen.GetWorkingArea(pt); if (pt.X + Width > area.Right) pt.X = area.Right - Width; if (pt.Y + Height > area.Bottom) pt.Y = area.Bottom - Height; popupHelper.ShowPopup(ownerForm, this, pt); } /// /// Initializes a new instance of the class with default settings. /// /// The main form that owns this popup form. public PopupWindow(Form ownerForm) : base() { this.ownerForm = ownerForm; popupHelper = new PopupWindowHelper(); popupHelper.AssignHandle(ownerForm.Handle); popupHelper.PopupCancel += PopupCancel; FormBorderStyle = FormBorderStyle.FixedToolWindow; ControlBox = false; StartPosition = FormStartPosition.Manual; ShowInTaskbar = false; } /// /// Handler which allows to prevent canceling of popup window /// /// Popup helper /// Event arguments protected virtual void PopupCancel(object sender, PopupCancelEventArgs e) { } } }