Better centering of the IP address edit box when first opened.

This commit is contained in:
Tim Young 2017-02-25 10:44:12 +03:00
parent f4ab85f359
commit d948be0a54
2 changed files with 37 additions and 28 deletions

View File

@ -40,68 +40,65 @@
// //
// lblIP // lblIP
// //
this.lblIP.Location = new System.Drawing.Point(14, 11); this.lblIP.Location = new System.Drawing.Point(19, 14);
this.lblIP.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblIP.Name = "lblIP"; this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(56, 14); this.lblIP.Size = new System.Drawing.Size(75, 17);
this.lblIP.TabIndex = 0; this.lblIP.TabIndex = 0;
this.lblIP.Text = "IP"; this.lblIP.Text = "IP";
this.lblIP.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.lblIP.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// lblNetmask // lblNetmask
// //
this.lblNetmask.Location = new System.Drawing.Point(12, 37); this.lblNetmask.Location = new System.Drawing.Point(16, 46);
this.lblNetmask.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblNetmask.Name = "lblNetmask"; this.lblNetmask.Name = "lblNetmask";
this.lblNetmask.Size = new System.Drawing.Size(58, 14); this.lblNetmask.Size = new System.Drawing.Size(77, 17);
this.lblNetmask.TabIndex = 1; this.lblNetmask.TabIndex = 1;
this.lblNetmask.Text = "Netmask"; this.lblNetmask.Text = "Netmask";
this.lblNetmask.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.lblNetmask.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// lblGateway // lblGateway
// //
this.lblGateway.Location = new System.Drawing.Point(12, 60); this.lblGateway.Location = new System.Drawing.Point(16, 74);
this.lblGateway.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblGateway.Name = "lblGateway"; this.lblGateway.Name = "lblGateway";
this.lblGateway.Size = new System.Drawing.Size(58, 14); this.lblGateway.Size = new System.Drawing.Size(77, 17);
this.lblGateway.TabIndex = 2; this.lblGateway.TabIndex = 2;
this.lblGateway.Text = "Gateway"; this.lblGateway.Text = "Gateway";
this.lblGateway.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.lblGateway.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
// //
// tbIPAddress // tbIPAddress
// //
this.tbIPAddress.Location = new System.Drawing.Point(85, 11); this.tbIPAddress.Location = new System.Drawing.Point(113, 14);
this.tbIPAddress.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tbIPAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.tbIPAddress.Name = "tbIPAddress"; this.tbIPAddress.Name = "tbIPAddress";
this.tbIPAddress.Size = new System.Drawing.Size(97, 20); this.tbIPAddress.Size = new System.Drawing.Size(128, 22);
this.tbIPAddress.TabIndex = 3; this.tbIPAddress.TabIndex = 3;
this.tbIPAddress.Validating += new System.ComponentModel.CancelEventHandler(this.tbIPAddress_Validating); this.tbIPAddress.Validating += new System.ComponentModel.CancelEventHandler(this.tbIPAddress_Validating);
// //
// tbNetmask // tbNetmask
// //
this.tbNetmask.Location = new System.Drawing.Point(85, 34); this.tbNetmask.Location = new System.Drawing.Point(113, 42);
this.tbNetmask.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tbNetmask.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.tbNetmask.Name = "tbNetmask"; this.tbNetmask.Name = "tbNetmask";
this.tbNetmask.Size = new System.Drawing.Size(97, 20); this.tbNetmask.Size = new System.Drawing.Size(128, 22);
this.tbNetmask.TabIndex = 4; this.tbNetmask.TabIndex = 4;
this.tbNetmask.Validating += new System.ComponentModel.CancelEventHandler(this.tbNetmask_Validating); this.tbNetmask.Validating += new System.ComponentModel.CancelEventHandler(this.tbNetmask_Validating);
// //
// tbGateway // tbGateway
// //
this.tbGateway.Location = new System.Drawing.Point(85, 58); this.tbGateway.Location = new System.Drawing.Point(113, 71);
this.tbGateway.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.tbGateway.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.tbGateway.Name = "tbGateway"; this.tbGateway.Name = "tbGateway";
this.tbGateway.Size = new System.Drawing.Size(97, 20); this.tbGateway.Size = new System.Drawing.Size(128, 22);
this.tbGateway.TabIndex = 5; this.tbGateway.TabIndex = 5;
this.tbGateway.Validating += new System.ComponentModel.CancelEventHandler(this.tbGateway_Validating); this.tbGateway.Validating += new System.ComponentModel.CancelEventHandler(this.tbGateway_Validating);
// //
// btnCancel // btnCancel
// //
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(14, 98); this.btnCancel.Location = new System.Drawing.Point(19, 121);
this.btnCancel.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnCancel.Name = "btnCancel"; this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(56, 19); this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 6; this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "Cancel"; this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true; this.btnCancel.UseVisualStyleBackColor = true;
@ -109,10 +106,10 @@
// //
// btnOK // btnOK
// //
this.btnOK.Location = new System.Drawing.Point(125, 98); this.btnOK.Location = new System.Drawing.Point(167, 121);
this.btnOK.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnOK.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnOK.Name = "btnOK"; this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(56, 19); this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 7; this.btnOK.TabIndex = 7;
this.btnOK.Text = "OK"; this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true; this.btnOK.UseVisualStyleBackColor = true;
@ -121,10 +118,10 @@
// IPAddressEntry // IPAddressEntry
// //
this.AcceptButton = this.btnOK; this.AcceptButton = this.btnOK;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.btnCancel; this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(195, 132); this.ClientSize = new System.Drawing.Size(260, 162);
this.Controls.Add(this.btnOK); this.Controls.Add(this.btnOK);
this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnCancel);
this.Controls.Add(this.tbGateway); this.Controls.Add(this.tbGateway);
@ -135,9 +132,10 @@
this.Controls.Add(this.lblIP); this.Controls.Add(this.lblIP);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Icon = global::EduNetworkBuilder.Properties.Resources.NBIco; this.Icon = global::EduNetworkBuilder.Properties.Resources.NBIco;
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "IPAddressEntry"; this.Name = "IPAddressEntry";
this.Text = "IP-Address Entry"; this.Text = "IP-Address Entry";
this.Shown += new System.EventHandler(this.IPAddressEntry_Shown);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

View File

@ -19,6 +19,7 @@ namespace EduNetworkBuilder
IPAddress DHCPInterface=null; IPAddress DHCPInterface=null;
bool WellDone = true; bool WellDone = true;
NetworkDevice ParentDevice = null; NetworkDevice ParentDevice = null;
Point StartLocation = new Point (50,50);
public IPAddressEntry(IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm) public IPAddressEntry(IPAddress toEdit, NetworkDevice ToEdit, Form ParentForm)
@ -27,7 +28,8 @@ namespace EduNetworkBuilder
LanguagifyComponents(); LanguagifyComponents();
if(ParentForm != null) if(ParentForm != null)
{ {
Location = new Point(ParentForm.Location.X + (ParentForm.Width / 2), ParentForm.Location.Y + (ParentForm.Height / 2)); Point NewPoint = new Point(ParentForm.Location.X + (ParentForm.Width / 2), ParentForm.Location.Y + (ParentForm.Height / 2));
StartLocation = NewPoint;
} }
ParentDevice = ToEdit; ParentDevice = ToEdit;
Network myNet = NB.GetNetwork(); Network myNet = NB.GetNetwork();
@ -151,6 +153,7 @@ namespace EduNetworkBuilder
public bool Edit() public bool Edit()
{ {
Location = StartLocation;
ShowDialog(); ShowDialog();
return WellDone; return WellDone;
} }
@ -171,6 +174,7 @@ namespace EduNetworkBuilder
tbIPAddress.Enabled = false; tbIPAddress.Enabled = false;
tbNetmask.Enabled = false; tbNetmask.Enabled = false;
} }
Location = StartLocation;
ShowDialog(); ShowDialog();
return WellDone; return WellDone;
} }
@ -247,5 +251,12 @@ namespace EduNetworkBuilder
{ {
this.Text = text; this.Text = text;
} }
private void IPAddressEntry_Shown(object sender, EventArgs e)
{
Point tLocation = new Point (StartLocation.X - Width, StartLocation.Y - Height);
if (tLocation.X < 0 || tLocation.Y < 0) tLocation = new Point(50, 50);
Location = tLocation;
}
} }
} }