Added TopMost option

This commit is contained in:
Jaex 2022-08-01 21:42:37 +03:00
parent 2228e300c9
commit d252c9345e
3 changed files with 4 additions and 2 deletions

View file

@ -27,7 +27,6 @@ private void InitializeComponent()
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "ShareX - Pin to screen";
this.TopMost = true;
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.PinToScreenForm_KeyUp);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PinToScreenForm_MouseUp);

View file

@ -114,6 +114,7 @@ private PinToScreenForm(PinToScreenOptions options)
ImageOpacity = Options.InitialOpacity;
InitializeComponent();
TopMost = Options.TopMost;
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
isDWMEnabled = NativeMethods.IsDWMEnabled();
@ -162,6 +163,7 @@ private void AutoSizeForm()
}
Point newLocation = Location;
SpecialWindowHandles insertAfter = Options.TopMost ? SpecialWindowHandles.HWND_TOPMOST : SpecialWindowHandles.HWND_TOP;
SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOACTIVATE;
if (Options.KeepCenterLocation)
@ -174,7 +176,7 @@ private void AutoSizeForm()
flags |= SetWindowPosFlags.SWP_NOMOVE;
}
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, newLocation.X, newLocation.Y, newSize.Width, newSize.Height, flags);
NativeMethods.SetWindowPos(Handle, (IntPtr)insertAfter, newLocation.X, newLocation.Y, newSize.Width, newSize.Height, flags);
Refresh();
}

View file

@ -36,6 +36,7 @@ public class PinToScreenOptions
public int OpacityStep { get; set; } = 10;
public ContentAlignment Placement { get; set; } = ContentAlignment.BottomRight;
public int PlacementOffset { get; set; } = 10;
public bool TopMost { get; set; } = true;
public bool KeepCenterLocation { get; set; } = true;
public bool ShowShadow { get; set; } = true;
public Color BackgroundColor { get; set; } = Color.White;