Ejemplo n.º 1
0
 private void foodEnterOrNr(tbpaste tb, KeyPressEventArgs e) //handles Enter for some food related custom textboxes(shortcut so u can enter food faster) that ALSO need to only accept Number Formats
 {
     if (e.KeyChar == 13)                                    //checks if Enter was typed
     {
         button_addFood.PerformClick();
         e.Handled = true;
     }
     else if (e.KeyChar == '.')  //check if Dot was typed
     {
         if (tb.dot)             //ignores it by setting handling event as handled If a dot already was typed/exists in tb
         {
             e.Handled = true;
         }
         else
         {
             e.Handled = false;
             tb.dot    = true;
         }
     }
     else if (Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar))  //checks if a Number of Control key was typed
     {
         e.Handled = false;
     }
     else
     {
         e.Handled = true;   //ignores if not(like a letter etc. - chars that shouldn't be here)
     }
 }
Ejemplo n.º 2
0
 private void checkNotePasted(tbpaste tb)                //check if Text entered(either by paste or text change in general) into custom textbox tb is a Note Score Format: ~+-
 {
     if (tb.pasted)                                      //checks if paste event happened in tb
     {
         if (!new Regex(@"^[~\+\-]+$").IsMatch(tb.Text)) //case format is not correct: resets text and flags
         {
             MessageBox.Show($"Invalid value pasted for {tb.Name} - Not a valid Score!");
             tb.pasted = false;
             tb.Clear();
             return;
         }
         tb.pasted = false;
     }
 }
Ejemplo n.º 3
0
 private void checkNumberPasted(tbpaste tb)               //check if Text entered(either by paste or text change in general) into custom textbox tb is a Number Format: 11 or 1/11 or 11.1
 {
     if (tb.pasted)                                       //checks if paste event happened in tb
     {
         if (!MainForm.regexNumberValue.IsMatch(tb.Text)) //case not a number format: resets textbox text and flags
         {
             MessageBox.Show($"Invalid value pasted for {tb.Name} - Not a valid Number!");
             tb.pasted = false;
             tb.dot    = false;
             tb.Clear();
             return;
         }
         tb.pasted = false;      //resets pasted flag if number format
     }
     if (tb.Text.Contains('.'))  //checks if dot is present(whether pasted or textchanged in general) and sets flag for that to be true to stop another dot from being typed in future (there's only 1 dot possible for number format to have)
     {
         tb.dot = true;
     }
     else
     {
         tb.dot = false;
     }
 }