Fixed start up sidepanel position.

This commit is contained in:
Lorenz Cuno Klopfenstein 2011-03-27 22:19:57 +02:00
parent 726cfcb755
commit 4d842bfe6d
2 changed files with 13 additions and 4 deletions

View file

@ -22,8 +22,8 @@ namespace OnTopReplica {
_sidePanelContainer = new SidePanelContainer(this);
_sidePanelContainer.SetSidePanel(panel);
_sidePanelContainer.Location = ComputeSidePanelLocation(_sidePanelContainer);
_sidePanelContainer.Show(this);
AdjustSidePanelLocation();
}
/// <summary>
@ -62,13 +62,21 @@ namespace OnTopReplica {
if (!IsSidePanelOpen)
return;
_sidePanelContainer.Location = ComputeSidePanelLocation(_sidePanelContainer);
}
/// <summary>
/// Computes the target location of a side panel form that ensures it is visible on the current
/// screen that contains the main form.
/// </summary>
private Point ComputeSidePanelLocation(Form sidePanel) {
//Check if moving the panel on the form's right would put it off-screen
var screen = Screen.FromControl(this);
if (Location.X + Width + _sidePanelContainer.Width > screen.WorkingArea.Right) {
_sidePanelContainer.Location = new Point(Location.X - _sidePanelContainer.Width, Location.Y);
if (Location.X + Width + sidePanel.Width > screen.WorkingArea.Right) {
return new Point(Location.X - sidePanel.Width, Location.Y);
}
else {
_sidePanelContainer.Location = new Point(Location.X + Width, Location.Y);
return new Point(Location.X + Width, Location.Y);
}
}

View file

@ -35,6 +35,7 @@
this.Name = "SidePanelContainer";
this.Padding = new System.Windows.Forms.Padding(6);
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Side Panel container";
this.TopMost = true;
this.ResumeLayout(false);