UIForm移动到顶最大化,移动范围判断
This commit is contained in:
parent
19ec4fcfa4
commit
361af57295
BIN
Bin/SunnyUI.dll
BIN
Bin/SunnyUI.dll
Binary file not shown.
BIN
Bin/SunnyUI.pdb
BIN
Bin/SunnyUI.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,22 +1,22 @@
|
||||
/******************************************************************************
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2020 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@qq.com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UIForm.cs
|
||||
* 文件说明: 窗体基类
|
||||
* 当前版本: V2.2
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
* SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。
|
||||
* CopyRight (C) 2012-2020 ShenYongHua(沈永华).
|
||||
* QQ群:56829229 QQ:17612584 EMail:SunnyUI@qq.com
|
||||
*
|
||||
* Blog: https://www.cnblogs.com/yhuse
|
||||
* Gitee: https://gitee.com/yhuse/SunnyUI
|
||||
* GitHub: https://github.com/yhuse/SunnyUI
|
||||
*
|
||||
* SunnyUI.dll can be used for free under the GPL-3.0 license.
|
||||
* If you use this code, please keep this note.
|
||||
* 如果您使用此代码,请保留此说明。
|
||||
******************************************************************************
|
||||
* 文件名称: UIForm.cs
|
||||
* 文件说明: 窗体基类
|
||||
* 当前版本: V2.2
|
||||
* 创建日期: 2020-01-01
|
||||
*
|
||||
* 2020-01-01: V2.2.0 增加文件说明
|
||||
******************************************************************************/
|
||||
|
||||
using System;
|
||||
@ -384,31 +384,37 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
private Size size;
|
||||
private Point mLocation; // 缩放前的窗体位置
|
||||
private Point location;
|
||||
|
||||
private void ShowMaximize()
|
||||
private int GetMouseInScreen(Point mousePos)
|
||||
{
|
||||
int screenIndex = 0;
|
||||
for (int i = 0; i < Screen.AllScreens.Length; i++)
|
||||
{
|
||||
if (MousePos.InRect(Screen.AllScreens[i].Bounds))
|
||||
if (mousePos.InRect(Screen.AllScreens[i].Bounds))
|
||||
{
|
||||
screenIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return screenIndex;
|
||||
}
|
||||
|
||||
private void ShowMaximize()
|
||||
{
|
||||
int screenIndex = GetMouseInScreen(MousePosition);
|
||||
Screen screen = Screen.AllScreens[screenIndex];
|
||||
if (windowState == FormWindowState.Normal)
|
||||
{
|
||||
size = Size;
|
||||
mLocation = Location;
|
||||
location = Location;
|
||||
|
||||
Width = ShowFullScreen ? screen.Bounds.Width : screen.WorkingArea.Width;
|
||||
Height = ShowFullScreen ? screen.Bounds.Height : screen.WorkingArea.Height;
|
||||
Left = screen.Bounds.Left;
|
||||
Top = screen.Bounds.Top;
|
||||
StartPosition = FormStartPosition.Manual;
|
||||
//StartPosition = FormStartPosition.Manual;
|
||||
SetFormRoundRectRegion(this, 0);
|
||||
|
||||
windowState = FormWindowState.Maximized;
|
||||
@ -419,12 +425,13 @@ namespace Sunny.UI
|
||||
{
|
||||
size = new Size(800, 600);
|
||||
}
|
||||
if (mLocation.IsEmpty)
|
||||
{
|
||||
mLocation = screen.WorkingArea.Location;
|
||||
}
|
||||
|
||||
Size = size;
|
||||
Location = mLocation;
|
||||
Point center = new Point(screen.Bounds.Left + screen.WorkingArea.Width / 2 - Size.Width / 2,
|
||||
screen.Bounds.Top + screen.WorkingArea.Height / 2 - Size.Height / 2);
|
||||
|
||||
if (location.X == 0 && location.Y == 0) location = center;
|
||||
Location = StartPosition == FormStartPosition.CenterScreen ? center : location;
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
SetFormRoundRectRegion(this, ShowRadius ? 5 : 0);
|
||||
windowState = FormWindowState.Normal;
|
||||
@ -433,7 +440,6 @@ namespace Sunny.UI
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private Point MousePos;
|
||||
private bool FormMoveMouseDown;
|
||||
private Point FormLocation; //form的location
|
||||
private Point mouseOffset; //鼠标的按下位置
|
||||
@ -445,6 +451,7 @@ namespace Sunny.UI
|
||||
if (InControlBox || InMaxBox || InMinBox) return;
|
||||
if (!ShowTitle) return;
|
||||
if (e.Y > Padding.Top) return;
|
||||
if (windowState == FormWindowState.Maximized) return;
|
||||
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
@ -472,27 +479,25 @@ namespace Sunny.UI
|
||||
|
||||
if (FormMoveMouseDown)
|
||||
{
|
||||
int screenIndex = 0;
|
||||
for (int i = 0; i < Screen.AllScreens.Length; i++)
|
||||
if (MousePosition.Y <= 0 && MaximizeBox)
|
||||
{
|
||||
if (MousePos.InRect(Screen.AllScreens[i].Bounds))
|
||||
{
|
||||
screenIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Screen screen = Screen.AllScreens[screenIndex];
|
||||
if (MousePosition.Y == 0 && MaximizeBox)
|
||||
if (windowState == FormWindowState.Normal)
|
||||
{
|
||||
ShowMaximize();
|
||||
}
|
||||
if(Top < screen.WorkingArea.Top) // 防止窗体上移时标题栏超出容器,导致后续无法移动
|
||||
}
|
||||
else
|
||||
{
|
||||
int screenIndex = GetMouseInScreen(MousePosition);
|
||||
Screen screen = Screen.AllScreens[screenIndex];
|
||||
if (Top < screen.WorkingArea.Top) // 防止窗体上移时标题栏超出容器,导致后续无法移动
|
||||
{
|
||||
Top = screen.WorkingArea.Top;
|
||||
}
|
||||
else if(Top > screen.WorkingArea.Bottom) // 防止窗体下移时标题栏超出容器,导致后续无法移动
|
||||
if (Top > screen.WorkingArea.Bottom - TitleHeight) // 防止窗体下移时标题栏超出容器,导致后续无法移动
|
||||
{
|
||||
Top = screen.WorkingArea.Bottom - 10;
|
||||
Top = screen.WorkingArea.Bottom - TitleHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -501,30 +506,13 @@ namespace Sunny.UI
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs e)
|
||||
{
|
||||
MousePos = PointToScreen(e.Location);
|
||||
|
||||
if (FormMoveMouseDown)
|
||||
{
|
||||
if (this.windowState == FormWindowState.Maximized)
|
||||
{
|
||||
Point pt = MousePosition;
|
||||
int MaximizedWidth = Width;
|
||||
int LocationX = Left;
|
||||
ShowMaximize();
|
||||
// 计算等比例缩放后,鼠标与原位置的相对位移
|
||||
mouseOffset.X -= Math.Abs(mouseOffset.X) - (mouseOffset.X - LocationX) * Width / MaximizedWidth;
|
||||
int offsetX = mouseOffset.X - pt.X;
|
||||
int offsetY = mouseOffset.Y - pt.Y;
|
||||
Location = new Point(offsetX, offsetY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Point pt = MousePosition;
|
||||
int offsetX = mouseOffset.X - pt.X;
|
||||
int offsetY = mouseOffset.Y - pt.Y;
|
||||
Location = new Point(FormLocation.X - offsetX, FormLocation.Y - offsetY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FormBorderStyle == FormBorderStyle.None)
|
||||
@ -596,7 +584,8 @@ namespace Sunny.UI
|
||||
return;
|
||||
}
|
||||
|
||||
//Color titleColor = rectColor;// IsDesignMode ? rectColor : IsActive ? rectColor : Color.FromArgb(173, 178, 181);
|
||||
//Color titleColor = rectColor;// IsDesignMode ? rectColor : IsActive ? rectColor : Color.From
|
||||
//Argb(173, 178, 181);
|
||||
|
||||
if (ShowTitle)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user