Skip to content

Commit 5c2262e

Browse files
committed
fixed position with desktop shortcut close to taskbar
1 parent 5a56fd4 commit 5c2262e

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

main/Forms/frmMain.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ private void frmMain_Load(object sender, EventArgs e)
8585
// Sets location of form
8686
private void SetLocation()
8787
{
88+
//System.Diagnostics.Debugger.Launch();
89+
8890
List<Rectangle> taskbarList = FindDockedTaskBars();
8991
Rectangle taskbar = new Rectangle();
9092
Rectangle screen = new Rectangle();
@@ -141,23 +143,25 @@ private void SetLocation()
141143
locationy = mouseClick.Y - this.Height - 20;
142144
locationx = mouseClick.X - (this.Width / 2);
143145

144-
this.Location = new Point(locationx, locationy);
145-
// If form goes over screen edge
146-
if (this.Left < screen.Left)
147-
this.Left = screen.Left + 10;
148-
if (this.Top < screen.Top)
149-
this.Top = screen.Top + 10;
150-
if (this.Right > screen.Right)
151-
this.Left = screen.Right - this.Width - 10;
152-
// If form goes over taskbar
153-
if (taskbar.Contains(this.Left, this.Top) && taskbar.Contains(this.Right, this.Top)) // Top taskbar
154-
this.Top = screen.Top + 10 + taskbar.Height;
155-
if (taskbar.Contains(this.Left, this.Top)) // Left taskbar
156-
this.Left = screen.Left + 10 + taskbar.Width;
157-
if (taskbar.Contains(this.Right, this.Top)) // Right taskbar
158-
this.Left = screen.Right - this.Width - 10 - taskbar.Width;
159146
}
160147

148+
this.Location = new Point(locationx, locationy);
149+
150+
// If form goes over screen edge
151+
if (this.Left < screen.Left)
152+
this.Left = screen.Left + 10;
153+
if (this.Top < screen.Top)
154+
this.Top = screen.Top + 10;
155+
if (this.Right > screen.Right)
156+
this.Left = screen.Right - this.Width - 10;
157+
// If form goes over taskbar
158+
if (taskbar.Contains(this.Left, this.Top) && taskbar.Contains(this.Right, this.Top)) // Top taskbar
159+
this.Top = screen.Top + 10 + taskbar.Height;
160+
if (taskbar.Contains(this.Left, this.Top)) // Left taskbar
161+
this.Left = screen.Left + 10 + taskbar.Width;
162+
if (taskbar.Contains(this.Right, this.Top)) // Right taskbar
163+
this.Left = screen.Right - this.Width - 10 - taskbar.Width;
164+
161165
}
162166
else // Hidded taskbar
163167
{

0 commit comments

Comments
 (0)