Center toolbar

This commit is contained in:
Jaex 2023-10-08 08:06:25 +03:00
parent 4cfe3eb2d3
commit 5fb0493256

View file

@ -214,11 +214,41 @@ protected override void Dispose(bool disposing)
private void UpdateControls()
{
int toolbarMargin = 10;
tsMain.Visible = ClientRectangle.Contains(PointToClient(MousePosition)) &&
ClientRectangle.Contains(tsMain.Bounds.SizeOffset(tsMain.Location.X, tsMain.Location.Y));
ClientRectangle.Contains(new Rectangle(0, 0, (Options.Border ? Options.BorderSize * 2 : 0) + tsMain.Width + toolbarMargin * 2,
(Options.Border ? Options.BorderSize * 2 : 0) + tsMain.Height + toolbarMargin));
tslScale.Text = ImageScale + "%";
}
private void AutoSizeForm()
{
Size previousSize = Size;
Size newSize = FormSize;
Point newLocation = Location;
IntPtr insertAfter = Options.TopMost ? (IntPtr)NativeConstants.HWND_TOPMOST : (IntPtr)NativeConstants.HWND_TOP;
SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOSENDCHANGING;
if (Options.KeepCenterLocation)
{
Point locationOffset = new Point((previousSize.Width - newSize.Width) / 2, (previousSize.Height - newSize.Height) / 2);
newLocation = new Point(newLocation.X + locationOffset.X, newLocation.Y + locationOffset.Y);
}
else
{
flags |= SetWindowPosFlags.SWP_NOMOVE;
}
NativeMethods.SetWindowPos(Handle, insertAfter, newLocation.X, newLocation.Y, newSize.Width, newSize.Height, flags);
tsMain.Location = new Point(Width / 2 - tsMain.Width / 2, Options.Border ? Options.BorderSize : 0);
UpdateControls();
Refresh();
}
private void SetHandCursor(bool grabbing)
{
if (grabbing)
@ -243,32 +273,6 @@ private void ResetImage()
ImageOpacity = 100;
}
private void AutoSizeForm()
{
Size previousSize = Size;
Size newSize = FormSize;
Point newLocation = Location;
IntPtr insertAfter = Options.TopMost ? (IntPtr)NativeConstants.HWND_TOPMOST : (IntPtr)NativeConstants.HWND_TOP;
SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOSENDCHANGING;
if (Options.KeepCenterLocation)
{
Point locationOffset = new Point((previousSize.Width - newSize.Width) / 2, (previousSize.Height - newSize.Height) / 2);
newLocation = new Point(newLocation.X + locationOffset.X, newLocation.Y + locationOffset.Y);
}
else
{
flags |= SetWindowPosFlags.SWP_NOMOVE;
}
NativeMethods.SetWindowPos(Handle, insertAfter, newLocation.X, newLocation.Y, newSize.Width, newSize.Height, flags);
UpdateControls();
Refresh();
}
private void ToggleMinimize()
{
Minimized = !Minimized;