Beispiel #1
0
        internal void ShowInTaskbar(int x, int y)
        {
            base.WorkingAreaConstrained = false;
            Rectangle rect   = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveLeft);
            Rectangle bounds = Screen.FromRectangle(rect).Bounds;

            if (rect.Y < bounds.Y)
            {
                rect = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.BelowLeft);
            }
            else if (rect.X < bounds.X)
            {
                rect = base.CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveRight);
            }
            rect = WindowsFormsUtils.ConstrainToBounds(bounds, rect);
            base.Show(rect.X, rect.Y);
        }
        internal void ShowInTaskbar(int x, int y)
        {
            // we need to make ourselves a topmost window
            WorkingAreaConstrained = false;
            Rectangle bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveLeft);
            Rectangle screenBounds = Screen.FromRectangle(bounds).Bounds;
            if (bounds.Y < screenBounds.Y)
            {
                bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.BelowLeft);
            }
            else if (bounds.X < screenBounds.X)
            {
                bounds = CalculateDropDownLocation(new Point(x, y), ToolStripDropDownDirection.AboveRight);
            }
            bounds = WindowsFormsUtils.ConstrainToBounds(screenBounds, bounds);

            Show(bounds.X, bounds.Y);
        }
        protected override void SetBoundsCore(int argX, int argY, int argWidth, int argHeight, BoundsSpecified specified)
        {
            // Fix location
            var workingArea = Screen.PrimaryScreen.WorkingArea;
            var newBounds   = WindowsFormsUtils.ConstrainToBounds(workingArea, new Rectangle(argX, argY, argWidth, argHeight));
            var xFixed      = argX != newBounds.X;

            // TODO: need some code to prevent child going outside of screen.

            /*if (OwnerItem != null)
             * {
             *  var parentDropDown = OwnerItem.Owner as ToolStripDropDown;
             *  if (parentDropDown != null && direction == ToolStripDropDownDirection.Right)
             *  {
             *      // TODO: need to add other direction. Should be ToolStripDropDownItem, but the problem is that
             *      // it's invoked after Graphics.MeasureString, which can only be done on paint thread.
             *      if (xFixed && newBounds.X + newBounds.Width - 2 >= parentDropDown.Location.X)
             *          newBounds = new Rectangle(parentDropDown.Location.X - argWidth + 2, newBounds.Y, newBounds.Width, newBounds.Height);
             *  }
             * }*/

            base.SetBoundsCore(newBounds.X, newBounds.Y, newBounds.Width, newBounds.Height, specified);
        }