credential manager and cred editor windows now start in the middle of their parent window

This commit is contained in:
David Sparer
2017-01-23 11:39:23 -07:00
parent 7b851e7ac8
commit 9c4672fd68
6 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
using System.Drawing;
using System.Windows.Forms;
namespace mRemoteNG.UI
{
public static class FormExtensions
{
public static void CenterOnTarget(this Form formToMove, Form formToCenterOn)
{
var targetFormCenterX = formToCenterOn.Location.X + formToCenterOn.Width/2;
var targetFormCenterY = formToCenterOn.Location.Y + formToCenterOn.Height/2;
var thisFormCenterX = formToMove.Location.X + formToMove.Width/2;
var thisFormCenterY = formToMove.Location.Y + formToMove.Height/2;
formToMove.Location = new Point(targetFormCenterX - thisFormCenterX, targetFormCenterY - thisFormCenterY);
}
}
}

View File

@@ -163,6 +163,7 @@
this.Controls.Add(this.textBoxTitle);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "CredentialEditorForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Credential Editor";
this.ResumeLayout(false);
this.PerformLayout();

View File

@@ -112,6 +112,7 @@
this.Controls.Add(this.objectListView1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "CredentialManagerForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Credential Manager";
((System.ComponentModel.ISupportInitialize)(this.objectListView1)).EndInit();
this.ResumeLayout(false);

View File

@@ -52,6 +52,7 @@ namespace mRemoteNG.UI.Forms
if (clickedCredential == null) return;
var credentialEditorForm = new CredentialEditorForm(clickedCredential);
credentialEditorForm.ChangesAccepted += (o, args) => RaiseCredentialsChangedEvent(o);
credentialEditorForm.CenterOnTarget(this);
credentialEditorForm.Show(this);
}

View File

@@ -1263,6 +1263,7 @@ namespace mRemoteNG.UI.Forms
{
var credentialManager = new CredentialManagerForm(_credentialRecords);
credentialManager.CredentialsChanged += (o, args) => SaveCredentialList();
credentialManager.CenterOnTarget(this);
credentialManager.Show();
}

View File

@@ -274,6 +274,7 @@
<Compile Include="UI\Controls\ToolStripSplitButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="UI\FormExtensions.cs" />
<Compile Include="UI\Forms\CredentialEditorForm.cs">
<SubType>Form</SubType>
</Compile>