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.8 kB

9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 bool maximized;
  22. public LogViewerConfig()
  23. {
  24. fontName = "Consolas";
  25. fontSize = 8;
  26. bgColor = "black";
  27. textColor = "white";
  28. topMost = false;
  29. wrapText = false;
  30. toolbarShown = false;
  31. width = 600;
  32. height = 400;
  33. left = GetBestLeft();
  34. top = GetBestTop();
  35. maximized = true;
  36. }
  37. // Use GetBestTop() and GetBestLeft() to ensure the log viwer form can be always display IN screen.
  38. public int GetBestLeft()
  39. {
  40. width = (width >= 400) ? width : 400; // set up the minimum size
  41. return Screen.PrimaryScreen.WorkingArea.Width - width;
  42. }
  43. public int GetBestTop()
  44. {
  45. height = (height >= 200) ? height : 200; // set up the minimum size
  46. return Screen.PrimaryScreen.WorkingArea.Height - height;
  47. }
  48. public Font GetFont()
  49. {
  50. try
  51. {
  52. return new Font(fontName, fontSize, FontStyle.Regular);
  53. }
  54. catch (Exception)
  55. {
  56. return new Font("Console", 8F);
  57. }
  58. }
  59. public void SetFont(Font font)
  60. {
  61. fontName = font.Name;
  62. fontSize = font.Size;
  63. }
  64. public Color GetBackgroundColor()
  65. {
  66. try
  67. {
  68. return ColorTranslator.FromHtml(bgColor);
  69. }
  70. catch (Exception)
  71. {
  72. return ColorTranslator.FromHtml("black");
  73. }
  74. }
  75. public void SetBackgroundColor(Color color)
  76. {
  77. bgColor = ColorTranslator.ToHtml(color);
  78. }
  79. public Color GetTextColor()
  80. {
  81. try
  82. {
  83. return ColorTranslator.FromHtml(textColor);
  84. }
  85. catch (Exception)
  86. {
  87. return ColorTranslator.FromHtml("white");
  88. }
  89. }
  90. public void SetTextColor(Color color)
  91. {
  92. textColor = ColorTranslator.ToHtml(color);
  93. }
  94. }
  95. }