📄 formmain.cs
字号:
this.lblStreet.Location = new System.Drawing.Point(8, 6);
this.lblStreet.Size = new System.Drawing.Size(56, 16);
this.lblStreet.Text = "Street";
this.lblStreet.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// textSP
//
this.textSP.Location = new System.Drawing.Point(72, 46);
this.textSP.Size = new System.Drawing.Size(40, 22);
this.textSP.Text = "";
//
// textCity
//
this.textCity.Location = new System.Drawing.Point(72, 23);
this.textCity.Size = new System.Drawing.Size(152, 22);
this.textCity.Text = "";
this.textCity.Validated += new System.EventHandler(this.textCity_Validated);
//
// textStreet
//
this.textStreet.Location = new System.Drawing.Point(72, 0);
this.textStreet.Size = new System.Drawing.Size(152, 22);
this.textStreet.Text = "";
//
// lblPC
//
this.lblPC.Location = new System.Drawing.Point(120, 49);
this.lblPC.Size = new System.Drawing.Size(24, 20);
this.lblPC.Text = "PC";
this.lblPC.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// textPC
//
this.textPC.Location = new System.Drawing.Point(152, 47);
this.textPC.Size = new System.Drawing.Size(72, 22);
this.textPC.Text = "";
//
// panelMemberType
//
this.panelMemberType.Controls.Add(this.optAssociate);
this.panelMemberType.Controls.Add(this.optChild);
this.panelMemberType.Controls.Add(this.optAdult);
this.panelMemberType.Location = new System.Drawing.Point(36, 5);
this.panelMemberType.Size = new System.Drawing.Size(200, 32);
//
// optAssociate
//
this.optAssociate.Location = new System.Drawing.Point(112, 8);
this.optAssociate.Size = new System.Drawing.Size(80, 20);
this.optAssociate.Text = "Associate";
this.optAssociate.CheckedChanged += new System.EventHandler(this.optAny_CheckedChanged);
//
// optChild
//
this.optChild.Location = new System.Drawing.Point(64, 8);
this.optChild.Size = new System.Drawing.Size(48, 20);
this.optChild.Text = "Child";
this.optChild.CheckedChanged += new System.EventHandler(this.optAny_CheckedChanged);
//
// optAdult
//
this.optAdult.Location = new System.Drawing.Point(8, 8);
this.optAdult.Size = new System.Drawing.Size(56, 20);
this.optAdult.Text = "Adult";
this.optAdult.CheckedChanged += new System.EventHandler(this.optAny_CheckedChanged);
//
// cmdAdd
//
this.cmdAdd.Location = new System.Drawing.Point(196, 245);
this.cmdAdd.Size = new System.Drawing.Size(40, 20);
this.cmdAdd.Text = "Add";
this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click);
//
// FormRegister
//
this.Controls.Add(this.panelChild);
this.Controls.Add(this.panelWho);
this.Controls.Add(this.panelSponsor);
this.Controls.Add(this.panelAddress);
this.Controls.Add(this.panelMemberType);
this.Controls.Add(this.cmdAdd);
this.Menu = this.mainMenu1;
this.Text = "Register";
this.Load += new System.EventHandler(this.FormRegister_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new FormRegister());
}
private void FormRegister_Load(object sender,
EventArgs e)
{
// Clear the input fields
ClearInputFields(this);
// Place the option buttons in a line along the
// top of the form, right justified.
PositionOptionButtons();
// Co-locate the City combobox and
// its associated text box.
textCity.Bounds = cboxCity.Bounds;
// Add the "(new Entry)" item at to top of the list.
// Select it.
// Show the ComboBox
cboxCity.Items.Insert(0, "(new Entry)");
cboxCity.SelectedIndex = 0;
cboxCity.BringToFront();
// Default to an Adult entry.
this.optAdult.Checked = true;
}
private void optAny_CheckedChanged(object sender,
System.EventArgs e)
{
// Hide what you do not need,
// show what you do need.
panelSponsor.Visible =
optAssociate.Checked || optChild.Checked;
panelAddress.Visible =
optAdult.Checked || optAssociate.Checked;
panelChild.Visible = optChild.Checked;
// Position panels.
int topNext = panelWho.Bottom;
if (panelSponsor.Visible )
{
panelSponsor.Top = topNext;
topNext = panelSponsor.Bottom;
}
if (panelAddress.Visible )
{
panelAddress.Top = topNext;
topNext = panelAddress.Bottom;
}
if (panelChild.Visible )
{
panelChild.Top = topNext;
topNext = panelChild.Bottom;
}
}
private void cboxCity_SelectedIndexChanged(object sender,
EventArgs e)
{
// if ( the user requested free form test entry
if ( cboxCity.SelectedIndex == 0 )
{
// Clear the TextBox
// Show it
// Give it the focus.
textCity.Text = string .Empty;
textCity.BringToFront();
textCity.Focus();
}
}
private void textCity_Validated(object sender,
EventArgs e)
{
// The user has completed their data entry
// and that data has passed all edits.
if ( textCity.Text.Trim() != string.Empty )
{
// Add their entry to the ComboBox//s dropdown list.
// Select it.
// Show the ComboBox.
cboxCity.Items.Insert(1, textCity.Text);
cboxCity.SelectedIndex = 1;
}
cboxCity.BringToFront();
}
private void cmdAdd_Click(object sender, System.EventArgs e)
{
// Code to register a member goes here
// :
// :
genderMember =
optFemale.Checked ? "F" :
optMale.Checked ? "M" : "X";
// :
// :
ClearInputFields(this);
}
private void PositionOptionButtons()
{
// Place the option buttons in a line along the
// top of the form, right justified.
panelMemberType.BackColor = Color.Bisque;
panelMemberType.Height = optAdult.Height;
panelMemberType.Width = optAdult.Width
+ optAssociate.Width
+ optChild.Width;
panelMemberType.Location =
new Point(this.ClientRectangle.Width -
panelMemberType.Width, 0);
optAssociate.Location =
new Point(panelMemberType.ClientRectangle.Width -
optAssociate.Width, 0);
optChild.Location =
new Point(optAssociate.Left - optChild.Width, 0);
optAdult.Location =
new Point(optChild.Left - optAdult.Width, 0);
}
private void ClearInputFields(Control ctrlContainer)
{
ClearTextBoxes(ctrlContainer);
cboxCity.SelectedIndex = 0;
textID.Focus();
}
private void ClearTextBoxes(Control ctrlContainer)
{
foreach(Control theControl in ctrlContainer.Controls )
{
// Recursively perform this routine.
ClearInputFields(theControl);
// Clear all TextBoxes that are first
// level children of this control.
if (theControl.GetType().ToString() ==
"System.Windows.Forms.TextBox")
{
theControl.Text = string.Empty;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -