Example #1
0
        private void SetAutoCompleteLocation(TextBoxBase control, bool moveHorizontly)
        {
            Point     cursorLocation  = control.GetPositionFromCharIndex(control.SelectionStart);
            Screen    screen          = Screen.FromPoint(cursorLocation);
            Point     optimalLocation = new Point(control.PointToScreen(cursorLocation).X - 15, (int)(control.PointToScreen(cursorLocation).Y + Font.Size * 2 + 2));
            Rectangle desiredPlace    = new Rectangle(optimalLocation, this.Size);

            desiredPlace.Width = 152;

            if (desiredPlace.Left < screen.Bounds.Left)
            {
                desiredPlace.X = screen.Bounds.Left;
            }
            if (desiredPlace.Right > screen.Bounds.Right)
            {
                desiredPlace.X -= (desiredPlace.Right - screen.Bounds.Right);
            }
            if (desiredPlace.Bottom > screen.Bounds.Bottom)
            {
                desiredPlace.Y = cursorLocation.Y - 2 - desiredPlace.Height;
            }
            if (!moveHorizontly)
            {
                desiredPlace.X = this.Left;
            }

            this.Bounds = desiredPlace;
        }