Files
cameramanager/CSharpLibrary/FormsInterfaces/NumericPad.cs
T
2025-05-15 16:01:31 +02:00

163 lines
3.1 KiB
C#

/***************************************************/
// __ ______
/***************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
namespace IPadLibrary.FormsInterfaces {
public partial class NumericPad : Form {
/*******************************************************************************************/
/* Constructors and Initialization
/*******************************************************************************************/
#region Public Class Constructors
public NumericPad(string text) {
InitializeComponent(); // This is for the designer (not edit)
InizializeLocalData(); // This is for local data private/public
Display.Text = text.Trim();
}
public NumericPad() :
this("0") {
}
#endregion
/*******************************************************************************************/
/* Form Events
/*******************************************************************************************/
#region Form Events
private void KEY_Button_Click(object sender, EventArgs e) {
if ( Display.Text.Length >= MAX_DISPLAY_NUMBERS )
return;
if ( Display.Text == "0" )
Display.Text = ((Button) sender).Text;
else if ( Display.Text == "-0" )
Display.Text = "-" + ((Button) sender).Text;
else
Display.Text += ((Button) sender).Text;
}
private void BACKSPACE_Button_Click(object sender, EventArgs e) {
int len;
if ((len = Display.Text.Length) > 1) {
if (Display.Text[Display.Text.Length - 1] == '.')
dot = false;
Display.Text = Display.Text.Remove(len - 1);
}
else {
if (Display.PasswordChar != '*' )
Display.Text = "0";
else
Display.Text = "";
}
}
private void OK_Button_Click(object sender, EventArgs e) {
this.DialogResult = DialogResult.OK;
Close();
}
private void CANCEL_Button_Click(object sender, EventArgs e) {
this.DialogResult = DialogResult.Cancel;
Close();
}
private void CE_Button_Click(object sender, EventArgs e) {
dot = false;
if (Display.PasswordChar != '*')
Display.Text = "0";
else
Display.Text = "";
}
private void SIGN_Button_Click(object sender, EventArgs e) {
if ( Display.Text[0] == '-' )
Display.Text = Display.Text.Substring(1);
else
Display.Text = "-" + Display.Text;
}
private void DOT_Button_Click(object sender, EventArgs e) {
if ( !dot )
Display.Text += ".";
dot = true;
}
/// <summary>
/// Used to drawing the Form borders only.
/// </summary>
private void NumericPad_Paint(object sender, PaintEventArgs e) {
GeneralLibrary.DrawFormBorder(sender, e);
}
public void Close(int n) {
if ( n == 1 ) {
int height = this.ClientSize.Height;
int width = this.ClientSize.Width;
while ( this.ClientSize.Height > 10 ) {
this.Height -= 3;
Thread.Sleep(1);
}
while ( this.ClientSize.Width > 10 ) {
this.Width -= 2;
Thread.Sleep(1);
}
}
Close();
}
#endregion
} // end class
} // end namespace