Skip to content

Commit

Permalink
Panel will now recentre on main screen if it is not visible. Quick Ob…
Browse files Browse the repository at this point in the history
…servation window changed to centre on panel just like all other EAACP dialogs.
  • Loading branch information
Xio1996 committed Jan 30, 2025
1 parent fcdde45 commit e7e5a16
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 29 deletions.
1 change: 1 addition & 0 deletions EAACP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="StellariumControl.Designer.cs">
<DependentUpon>StellariumControl.cs</DependentUpon>
</Compile>
<Compile Include="WindowCentre.cs" />
<EmbeddedResource Include="Config.resx">
<DependentUpon>Config.cs</DependentUpon>
</EmbeddedResource>
Expand Down
2 changes: 1 addition & 1 deletion Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ public frmCP()
{
this.Width = Properties.Settings.Default.frmWidth;
this.Height = Properties.Settings.Default.frmHeight;
this.Left = Properties.Settings.Default.XPos;
this.Top = Properties.Settings.Default.YPos;

if (Screen.PrimaryScreen.Bounds.Width > Properties.Settings.Default.XPos + this.Width)
// Center the form on the screen, if the form is larger off the screen then center the form on the screen
WindowHelper.EnsureWindowVisible(this);

/* if (Screen.PrimaryScreen.Bounds.Width > Properties.Settings.Default.XPos + this.Width)
{
this.Left = Properties.Settings.Default.XPos;
if (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height > Properties.Settings.Default.YPos + this.Height)
Expand All @@ -113,7 +118,7 @@ public frmCP()
else
{
this.CenterToScreen();
}
} */
}

SetTimer();
Expand Down Expand Up @@ -472,7 +477,7 @@ private void btnQuickObs_Click(object sender, EventArgs e)

using (QuickObs formObs = new QuickObs())
{
formObs.TopMost = true;
formObs.TopMost = true;

// Associated objects
formObs.Controls["chkAssociated"].Visible = bAssociated;
Expand Down
2 changes: 1 addition & 1 deletion QuickObs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions QuickObs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@ public partial class QuickObs : Form
public QuickObs()
{
InitializeComponent();

if (Properties.Settings.Default.QOYPos == -1)
{
this.CenterToParent();
}
else
{
if (Screen.PrimaryScreen.Bounds.Width > Properties.Settings.Default.QOXPos + this.Width)
{
this.Left = Properties.Settings.Default.QOXPos;
if (System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height > Properties.Settings.Default.QOYPos + this.Height)
{
this.Top = Properties.Settings.Default.QOYPos;
}
else
{
this.CenterToParent();
}
}
else
{
this.CenterToParent();
}
}
}

private void btnCancel_Click(object sender, EventArgs e)
Expand Down
44 changes: 44 additions & 0 deletions WindowCentre.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EAACP
{
internal class WindowHelper
{
public static void EnsureWindowVisible(Form form, Form parent = null)
{
bool isVisible = false;

// Check if the window is at least partially visible on any screen
foreach (Screen screen in Screen.AllScreens)
{
if (screen.WorkingArea.IntersectsWith(form.Bounds))
{
isVisible = true;
return;
}
}

// If the window is not visible on any screen, center it on the primary screen
if (!isVisible)
{
if (parent != null)
{
form.StartPosition = FormStartPosition.CenterParent;
return;
}

var primary = Screen.PrimaryScreen;
var primaryWorkingArea = primary.WorkingArea;
int primaryCenterX = (primaryWorkingArea.Right - form.Width) / 2;
int primaryCenterY = (primaryWorkingArea.Bottom - form.Height) / 2;
form.Location = new Point(primaryCenterX, primaryCenterY);
}
}
}
}

0 comments on commit e7e5a16

Please sign in to comment.