GetPosition improvement

This commit is contained in:
Jaex 2020-08-04 19:44:26 +03:00
parent 67490d1ba9
commit 282b1425ec
3 changed files with 9 additions and 4 deletions

View file

@ -1062,10 +1062,15 @@ public static string GetUniqueID()
return Guid.NewGuid().ToString("N");
}
public static Point GetPosition(ContentAlignment placement, int offset, Size backgroundSize, Size objectSize)
{
return GetPosition(placement, new Point(offset, offset), backgroundSize, objectSize);
}
public static Point GetPosition(ContentAlignment placement, Point offset, Size backgroundSize, Size objectSize)
{
int midX = (backgroundSize.Width / 2) - (objectSize.Width / 2);
int midY = (backgroundSize.Height / 2) - (objectSize.Height / 2);
int midX = (int)Math.Round((backgroundSize.Width / 2f) - (objectSize.Width / 2f));
int midY = (int)Math.Round((backgroundSize.Height / 2f) - (objectSize.Height / 2f));
int right = backgroundSize.Width - objectSize.Width;
int bottom = backgroundSize.Height - objectSize.Height;

View file

@ -70,7 +70,7 @@ private DropForm(int size, int offset, ContentAlignment alignment, int opacity,
backgroundImage = DrawDropImage(DropSize);
Location = Helpers.GetPosition(DropAlignment, new Point(DropOffset, DropOffset), Screen.PrimaryScreen.WorkingArea.Size, backgroundImage.Size);
Location = Helpers.GetPosition(DropAlignment, DropOffset, Screen.PrimaryScreen.WorkingArea.Size, backgroundImage.Size);
SelectBitmap(backgroundImage, DropOpacity);
}

View file

@ -85,7 +85,7 @@ public NotificationForm(int duration, int fadeDuration, ContentAlignment placeme
size = new Size(textRenderSize.Width + (textPadding * 2), textRenderSize.Height + (textPadding * 2) + 2);
}
Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, size);
Point position = Helpers.GetPosition(placement, windowOffset, Screen.PrimaryScreen.WorkingArea.Size, size);
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X,
position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE);