コード例 #1
0
        void _titleBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isDragTitleBar && e.Button == MouseButtons.Left)
            {
                var mouse = Control.MousePosition;
                var w = Math.Abs(mouse.X - _point_mouseDown.X);
                var h = Math.Abs(mouse.Y - _point_mouseDown.Y);
                if (w >= _moveDistance || h >= _moveDistance)
                {
                    var rect = Parent.RectangleToScreen(Bounds);
                    var form = Floating();
                    _isDragTitleBar = false;

                    //マウス位置がタイトルバーの真ん中に来るようにする。
                    var x = mouse.X - (rect.Width / 2);
                    var y = mouse.Y - (SystemInformation.ToolWindowCaptionHeight / 2);
                    form.Bounds = new Rectangle(new Point(x, y), rect.Size);

                    //タイトルバー移動モードを作り出す
                    var input = new API_SendInput.INPUT();
                    input.type = API_SendInput.InputType.INPUT_MOUSE;
                    input.mi.dwFlags = API_SendInput.dwFlags.KEYEVENTF_KEYUP;
                    API_SendInput.SendInput(new API_SendInput.INPUT[] { input });
                }
            }
        }
コード例 #2
0
        void _titleBar_MouseLeave(object sender, EventArgs e)
        {
            if (_isDragTitleBar)
            {
                var rectangle = Parent.RectangleToScreen(Bounds);
                var floating = Floating();
                var mouse = Control.MousePosition;

                var x = mouse.X - (rectangle.Width / 2);
                var y = mouse.Y - (SystemInformation.ToolWindowCaptionHeight / 2);
                floating.Bounds = new Rectangle(new Point(x, y), rectangle.Size);
                _isDragTitleBar = false;

                var input = new API_SendInput.INPUT();
                input.type = API_SendInput.InputType.INPUT_MOUSE;
                input.mi.dwFlags = API_SendInput.dwFlags.KEYEVENTF_KEYUP;
                var inputs = new API_SendInput.INPUT[] { input };
                API_SendInput.SendInput(inputs);
            }
        }