.Net Applikation für den PC um den Arduino-FSRemotePowerSwitch zu steuern
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Utility.cs 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #region License
  2. /* Copyright (c) 2017 Fabrice Lacharme
  3. * This code was originally written by Jigar Desai
  4. * http://www.c-sharpcorner.com/article/knob-control-using-windows-forms-and-gdi/
  5. * Note that another implementation exists in vb.net by Blong
  6. * https://www.codeproject.com/Articles/2563/VB-NET-Knob-Control-using-Windows-Forms-and-GDI?msg=1884770#xx1884770xx
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to
  10. * deal in the Software without restriction, including without limitation the
  11. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  12. * sell copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #endregion
  27. #region Contact
  28. /*
  29. * Fabrice Lacharme
  30. * Email: fabrice.lacharme@gmail.com
  31. */
  32. #endregion
  33. using System;
  34. using System.Drawing;
  35. namespace KnobControl
  36. {
  37. /// <summary>
  38. /// Summary description for Utility.
  39. /// </summary>
  40. public class Utility
  41. {
  42. public static float GetRadian(float val)
  43. {
  44. return (float)(val * Math.PI / 180);
  45. }
  46. public static Color GetDarkColor(Color c,byte d)
  47. {
  48. byte r = 0 ;
  49. byte g = 0;
  50. byte b = 0 ;
  51. if (c.R > d) r = (byte)(c.R - d);
  52. if (c.G > d) g = (byte)(c.G - d);
  53. if (c.B > d) b = (byte)(c.B - d);
  54. Color c1 = Color.FromArgb(r,g,b);
  55. return c1;
  56. }
  57. public static Color GetLightColor(Color c,byte d)
  58. {
  59. byte r = 255 ;
  60. byte g = 255 ;
  61. byte b = 255 ;
  62. if (c.R + d < 255) r = (byte)(c.R + d);
  63. if (c.G + d < 255) g = (byte)(c.G + d);
  64. if (c.B + d < 255) b = (byte)(c.B + d);
  65. Color c2 = Color.FromArgb(r,g,b);
  66. return c2;
  67. }
  68. /// <summary>
  69. /// Method which checks is particular point is in rectangle
  70. /// </summary>
  71. /// <param name="p">Point to be Chaecked</param>
  72. /// <param name="r">Rectangle</param>
  73. /// <returns>true is Point is in rectangle, else false</returns>
  74. public static bool IsPointinRectangle(Point p ,Rectangle r)
  75. {
  76. bool flag = false;
  77. if (p.X > r.X && p.X < r.X + r.Width && p.Y > r.Y && p.Y < r.Y + r.Height)
  78. {
  79. flag = true;
  80. }
  81. return flag;
  82. }
  83. public static void DrawInsetCircle(ref Graphics g,Rectangle r,Pen p)
  84. {
  85. Pen p1 = new Pen(GetDarkColor(p.Color,50));
  86. Pen p2 = new Pen(GetLightColor(p.Color,50));
  87. for (int i=0;i<p.Width;i++)
  88. {
  89. Rectangle r1 = new Rectangle(r.X +i,r.Y +i,r.Width-i*2,r.Height-i*2);
  90. g.DrawArc(p2,r1,-45,180);
  91. g.DrawArc(p1,r1,135,180);
  92. }
  93. }
  94. }
  95. }