Esempio n. 1
0
        /// <summary>
        /// Position the form relative to the position of the bitmask control that called the form.
        /// </summary>
        /// <param name="bitmaskControl">The bitmask user control that alled this form.</param>
        protected void PositionTheForm(VariableControl bitmaskControl)
        {
            // Work out the preferred location where the form is to be positioned, this is to the right of the bit mask control so that it is aligned with the
            // selected control.

            // Get the location of the bitmask control in screen coordinates.
            Point preferredLocation = m_VariableControl.PointToScreen(bitmaskControl.ClientForm.Location);

            // Offset this by the width of the control plus a few minor X and Y adjustments.
            preferredLocation.Offset(new Point(bitmaskControl.Size.Width + AdjustX, AdjustY));

            int xCoordinate = preferredLocation.X;
            int yCoordinate = preferredLocation.Y;
            int formWidth   = this.Size.Width;
            int formHeight  = this.Size.Height;

            // Ensure that the form remains within the bounds of the screen.
            if ((yCoordinate + formHeight) > Screen.PrimaryScreen.WorkingArea.Height)
            {
                yCoordinate = Screen.PrimaryScreen.WorkingArea.Height - formHeight;
            }

            // Check whether the whole form can still fit on the screen and, if not, flip over to the other side of the control.
            if ((xCoordinate + formWidth) > Screen.PrimaryScreen.WorkingArea.Width)
            {
                // Flip over to the other side of the control.
                xCoordinate -= (formWidth + m_VariableControl.Size.Width + AdjustXFlipForm);
            }

            this.Location = new Point(xCoordinate, yCoordinate);
        }