Advertisement
realmaster42

[EBE] Bot Development Functions that help

Jul 3rd, 2017 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. // *realmaster42
  2. // Functions that may help bot development.
  3. // Incluiding: limit, negative, textBoxHint
  4.  
  5. // Limits specified value to the maximum and minimum. If exceeds, equal it to maximum. If below minimum, equal it to minimum.
  6. public int limit(int value, int max, int minimum = int.MinValue)
  7. {
  8. if (value > max)
  9. return max;
  10. else if (value < minimum)
  11. return minimum;
  12. else
  13. return value;
  14. }
  15.  
  16. // Creates the negative form of the other color.
  17. public Color negative(Color clr)
  18. {
  19. return Color.FromArgb(255 - clr.R, 255 - clr.G, 255 - clr.B);
  20. }
  21.  
  22. // Creates the negative form of the other color.
  23. public Color negative(int r = 255, int g = 255, int b = 255)
  24. {
  25. return Color.FromArgb(255 - r, 255 - g, 255 - b);
  26. }
  27.  
  28. // Activates "hint" mode for textbox. Basically, the text currently in it becomes a hint.
  29. public void textBoxHint(TextBox txtBox)
  30. {
  31. if (txtBox == null)
  32. throw new Exception("Attempted creating a hint on a null textbox.");
  33.  
  34. Color orig = txtBox.ForeColor;
  35. Color hint = Color.FromArgb(limit(orig.R + 111, 255), limit(orig.G + 111, 255), limit(orig.B + 111, 255));
  36. string defTxt = txtBox.Text;
  37.  
  38. txtBox.ForeColor = hint;
  39. txtBox.MouseClick += new MouseEventHandler(delegate
  40. {
  41. if (txtBox.Text == defTxt)
  42. txtBox.Text = "";
  43.  
  44. txtBox.ForeColor = orig;
  45. });
  46. txtBox.LostFocus += new EventHandler(delegate
  47. {
  48. if (string.IsNullOrEmpty(txtBox.Text) || string.IsNullOrWhiteSpace(txtBox.Text) || txtBox.Text == defTxt)
  49. {
  50. txtBox.Text = defTxt;
  51. txtBox.ForeColor = hint;
  52. }
  53. });
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement