/***************************************************/ // __ ______ /***************************************************/ 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) { // uso il carattere ',' perchè nel codice è usato il metodo 'CDbl' per eseguire la // cnversione da stringa a double: CDbl("3.5") -> 35, CDbl("3,5") -> 3.5 if ( !dot ) Display.Text += ","; dot = true; } /// /// Used to drawing the Form borders only. /// 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 private void Display_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) { } } // end class } // end namespace