📄 numberpickerinput.cs
字号:
this.button7.Size = new System.Drawing.Size(28, 25);
this.button7.TabIndex = 39;
this.button7.Text = "7";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// buttonEquals
//
this.buttonEquals.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.buttonEquals.Location = new System.Drawing.Point(67, 103);
this.buttonEquals.Name = "buttonEquals";
this.buttonEquals.Size = new System.Drawing.Size(47, 25);
this.buttonEquals.TabIndex = 38;
this.buttonEquals.Text = "=";
this.buttonEquals.Click += new System.EventHandler(this.buttonEquals_Click);
//
// NumberPickerInput
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(122, 135);
this.Controls.Add(this.buttonBackspace);
this.Controls.Add(this.buttonClear);
this.Controls.Add(this.button0);
this.Controls.Add(this.buttonDecimalSeparator);
this.Controls.Add(this.buttonPlusMinus);
this.Controls.Add(this.buttonPlus);
this.Controls.Add(this.buttonMinus);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.buttonTimes);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.buttonDivide);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.buttonEquals);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "NumberPickerInput";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Add number";
this.ResumeLayout(false);
}
#endregion
#region EventHandlers
/// <summary>
/// Method to be performed when clicking the 7 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button7_Click(object sender, System.EventArgs e)
{
this.AddCharacter('7');
}
/// <summary>
/// Method to be performed when clicking the 8 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button8_Click(object sender, System.EventArgs e)
{
this.AddCharacter('8');
}
/// <summary>
/// Method to be performed when clicking the 9 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button9_Click(object sender, System.EventArgs e)
{
this.AddCharacter('9');
}
/// <summary>
/// Method to be performed when clicking the 4 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button4_Click(object sender, System.EventArgs e)
{
this.AddCharacter('4');
}
/// <summary>
/// Method to be performed when clicking the 5 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button5_Click(object sender, System.EventArgs e)
{
this.AddCharacter('5');
}
/// <summary>
/// Method to be performed when clicking the 6 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button6_Click(object sender, System.EventArgs e)
{
this.AddCharacter('6');
}
/// <summary>
/// Method to be performed when clicking the 1 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button1_Click(object sender, System.EventArgs e)
{
this.AddCharacter('1');
}
/// <summary>
/// Method to be performed when clicking the 2 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button2_Click(object sender, System.EventArgs e)
{
this.AddCharacter('2');
}
/// <summary>
/// Method to be performed when clicking the 3 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button3_Click(object sender, System.EventArgs e)
{
this.AddCharacter('3');
}
/// <summary>
/// Method to be performed when clicking the 0 button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void button0_Click(object sender, System.EventArgs e)
{
this.AddCharacter('0');
}
/// <summary>
/// Method to be performed when clicking the decimal separator button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonDecimalSeparator_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator.Length; i++)
{
this.AddCharacter(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator[i]);
}
}
/// <summary>
/// Method to be performed when clicking the minus button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonPlusMinus_Click(object sender, System.EventArgs e)
{
if(this.result.Text.Length >= 1)
{
if(this.result.Text[0].Equals("-"))
this.result.Text = this.result.Text.Substring(1, this.result.Text.Length - 1);
else
this.result.Text = this.result.Text.Insert(0, "-");
}
}
/// <summary>
/// Method to be performed when clicking the clear button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonClear_Click(object sender, System.EventArgs e)
{
this.result.Text = "";
this.temporary = 0;
this.f = null;
this.clear = false;
}
/// <summary>
/// Method to be performed when clicking the backspace button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonBackspace_Click(object sender, System.EventArgs e)
{
this.result.Text = this.result.Text.Substring(0, this.result.Text.Length - 1);
}
/// <summary>
/// Method to be performed when clicking the equals button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonEquals_Click(object sender, System.EventArgs e)
{
this.Calculate();
this.Close();
}
/// <summary>
/// Method to be performed when clicking the divide button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonDivide_Click(object sender, System.EventArgs e)
{
this.Calculate();
this.temporary = Convert.ToDouble(this.result.Text);
this.f = new Function(Utilities.Divide);
this.clear = true;
}
/// <summary>
/// Method to be performed when clicking the times button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonTimes_Click(object sender, System.EventArgs e)
{
this.Calculate();
this.temporary = Convert.ToDouble(this.result.Text);
this.f = new Function(Utilities.Multiply);
this.clear = true;
}
/// <summary>
/// Method to be performed when clicking the minus button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonMinus_Click(object sender, System.EventArgs e)
{
this.Calculate();
this.temporary = Convert.ToDouble(this.result.Text);
this.f = new Function(Utilities.Substract);
this.clear = true;
}
/// <summary>
/// Method to be performed when clicking the plus button
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments which have been given</param>
private void buttonPlus_Click(object sender, System.EventArgs e)
{
this.Calculate();
this.temporary = Convert.ToDouble(this.result.Text);
this.f = new Function(Utilities.Add);
this.clear = true;
}
#endregion
#region Manipulators
/// <summary>
/// Method which is used for calculating the result of the function which has been pressed
/// with the temporary argument together with the last argument entered
/// </summary>
private void Calculate()
{
if(this.f != null)
{
// Calculate the new result based on the function
this.temporary = f(this.temporary, Convert.ToDouble(this.result.Text));
// Set the value of the textbox to the new result
this.result.Text = this.temporary.ToString();
}
this.f = null;
}
/// <summary>
/// Method that is used for adding a particular character to the textbox but first
/// checking if the textbox does not need to be cleared first
/// </summary>
/// <param name="c">The new character to add</param>
private void AddCharacter(char c)
{
if(this.clear)
{
this.result.Text = "";
this.clear = false;
}
this.result.Text += c;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -