You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogViewerConfig.cs 2.7 kB

9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Shadowsocks.View;
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Shadowsocks.Model
  6. {
  7. [Serializable]
  8. public class LogViewerConfig
  9. {
  10. public string fontName;
  11. public float fontSize;
  12. public string bgColor;
  13. public string textColor;
  14. public bool topMost;
  15. public bool wrapText;
  16. public bool toolbarShown;
  17. public int width;
  18. public int height;
  19. public int top;
  20. public int left;
  21. public LogViewerConfig()
  22. {
  23. fontName = "Consolas";
  24. fontSize = 8;
  25. bgColor = "black";
  26. textColor = "white";
  27. topMost = false;
  28. wrapText = false;
  29. toolbarShown = false;
  30. width = 600;
  31. height = 400;
  32. left = GetBestLeft();
  33. top = GetBestTop();
  34. }
  35. // Use GetBestTop() and GetBestLeft() to ensure the log viwer form can be always display IN screen.
  36. public int GetBestLeft()
  37. {
  38. width = (width >= 400) ? width : 400; // set up the minimum size
  39. return Screen.PrimaryScreen.WorkingArea.Width - width;
  40. }
  41. public int GetBestTop()
  42. {
  43. height = (height >= 200) ? height : 200; // set up the minimum size
  44. return Screen.PrimaryScreen.WorkingArea.Height - height;
  45. }
  46. public Font GetFont()
  47. {
  48. try
  49. {
  50. return new Font(fontName, fontSize, FontStyle.Regular);
  51. }
  52. catch (Exception)
  53. {
  54. return new Font("Console", 8F);
  55. }
  56. }
  57. public void SetFont(Font font)
  58. {
  59. fontName = font.Name;
  60. fontSize = font.Size;
  61. }
  62. public Color GetBackgroundColor()
  63. {
  64. try
  65. {
  66. return ColorTranslator.FromHtml(bgColor);
  67. }
  68. catch (Exception)
  69. {
  70. return ColorTranslator.FromHtml("black");
  71. }
  72. }
  73. public void SetBackgroundColor(Color color)
  74. {
  75. bgColor = ColorTranslator.ToHtml(color);
  76. }
  77. public Color GetTextColor()
  78. {
  79. try
  80. {
  81. return ColorTranslator.FromHtml(textColor);
  82. }
  83. catch (Exception)
  84. {
  85. return ColorTranslator.FromHtml("white");
  86. }
  87. }
  88. public void SetTextColor(Color color)
  89. {
  90. textColor = ColorTranslator.ToHtml(color);
  91. }
  92. }
  93. }