AppTheme.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using System.Drawing.Drawing2D;
  2. namespace TravelAgencyWinForms.Utils;
  3. public static class AppTheme
  4. {
  5. public static Color Background => Color.FromArgb(243, 251, 248);
  6. public static Color Surface => Color.White;
  7. public static Color SurfaceAlt => Color.FromArgb(234, 247, 243);
  8. public static Color Primary => Color.FromArgb(129, 203, 188);
  9. public static Color PrimaryDark => Color.FromArgb(54, 121, 111);
  10. public static Color PrimarySoft => Color.FromArgb(214, 240, 233);
  11. public static Color Border => Color.FromArgb(202, 227, 220);
  12. public static Color Text => Color.FromArgb(44, 67, 62);
  13. public static Color Muted => Color.FromArgb(99, 127, 121);
  14. public static Color Danger => Color.FromArgb(205, 110, 110);
  15. public static void ApplyForm(Form form, bool dialog = false)
  16. {
  17. form.BackColor = Background;
  18. form.Font = new Font("Segoe UI", 10F, FontStyle.Regular, GraphicsUnit.Point);
  19. form.ForeColor = Text;
  20. if (dialog)
  21. form.FormBorderStyle = FormBorderStyle.FixedDialog;
  22. }
  23. public static void StylePrimaryButton(Button button)
  24. {
  25. StyleButton(button, Primary, PrimaryDark, Color.White);
  26. }
  27. public static void StyleSecondaryButton(Button button)
  28. {
  29. StyleButton(button, Surface, Border, Text);
  30. }
  31. public static void StyleSelectedButton(Button button)
  32. {
  33. StyleButton(button, Primary, PrimaryDark, Color.White);
  34. }
  35. public static void StyleDangerButton(Button button)
  36. {
  37. StyleButton(button, Color.FromArgb(251, 235, 235), Danger, Danger);
  38. }
  39. private static void StyleButton(Button button, Color backColor, Color borderColor, Color foreColor)
  40. {
  41. button.FlatStyle = FlatStyle.Flat;
  42. button.FlatAppearance.BorderSize = 1;
  43. button.FlatAppearance.BorderColor = borderColor;
  44. button.BackColor = backColor;
  45. button.ForeColor = foreColor;
  46. button.Cursor = Cursors.Hand;
  47. button.Margin = new Padding(4);
  48. button.Padding = new Padding(8, 4, 8, 4);
  49. button.AutoSize = false;
  50. }
  51. public static void StyleMenuButton(Button button)
  52. {
  53. button.FlatStyle = FlatStyle.Flat;
  54. button.FlatAppearance.BorderSize = 0;
  55. button.BackColor = Color.Transparent;
  56. button.ForeColor = Color.White;
  57. button.Cursor = Cursors.Hand;
  58. button.TextAlign = ContentAlignment.MiddleLeft;
  59. button.Font = new Font("Segoe UI Semibold", 10F, FontStyle.Regular, GraphicsUnit.Point);
  60. button.Padding = new Padding(16, 0, 0, 0);
  61. }
  62. public static void StyleTextBox(TextBox textBox)
  63. {
  64. textBox.BorderStyle = BorderStyle.FixedSingle;
  65. textBox.BackColor = Color.White;
  66. textBox.ForeColor = Text;
  67. textBox.Margin = new Padding(4);
  68. }
  69. public static void StyleComboBox(ComboBox comboBox)
  70. {
  71. comboBox.FlatStyle = FlatStyle.Flat;
  72. comboBox.BackColor = Color.White;
  73. comboBox.ForeColor = Text;
  74. comboBox.Margin = new Padding(4);
  75. }
  76. public static void StyleGrid(DataGridView grid)
  77. {
  78. grid.BackgroundColor = Surface;
  79. grid.BorderStyle = BorderStyle.None;
  80. grid.GridColor = Border;
  81. grid.EnableHeadersVisualStyles = false;
  82. grid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
  83. grid.ColumnHeadersDefaultCellStyle.BackColor = PrimarySoft;
  84. grid.ColumnHeadersDefaultCellStyle.ForeColor = Text;
  85. grid.ColumnHeadersDefaultCellStyle.SelectionBackColor = Primary;
  86. grid.ColumnHeadersDefaultCellStyle.SelectionForeColor = Color.White;
  87. grid.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI Semibold", 10F);
  88. grid.DefaultCellStyle.SelectionBackColor = Color.FromArgb(224, 244, 239);
  89. grid.DefaultCellStyle.SelectionForeColor = Text;
  90. grid.DefaultCellStyle.BackColor = Color.White;
  91. grid.DefaultCellStyle.ForeColor = Text;
  92. grid.DefaultCellStyle.WrapMode = DataGridViewTriState.False;
  93. grid.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(249, 253, 252);
  94. grid.RowHeadersVisible = false;
  95. grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
  96. grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  97. grid.MultiSelect = false;
  98. grid.AllowUserToResizeRows = false;
  99. grid.AllowUserToAddRows = false;
  100. grid.AllowUserToDeleteRows = false;
  101. grid.ReadOnly = true;
  102. }
  103. public static Panel CreateCard(string title, string value, string? subtitle = null)
  104. {
  105. var panel = new Panel
  106. {
  107. Width = 220,
  108. Height = 108,
  109. BackColor = Surface,
  110. BorderStyle = BorderStyle.FixedSingle,
  111. Margin = new Padding(6),
  112. Padding = new Padding(14)
  113. };
  114. var titleLabel = new Label
  115. {
  116. Text = title,
  117. Dock = DockStyle.Top,
  118. Height = 22,
  119. ForeColor = Muted,
  120. Font = new Font("Segoe UI", 9.5F, FontStyle.Regular)
  121. };
  122. var valueLabel = new Label
  123. {
  124. Text = value,
  125. Dock = DockStyle.Top,
  126. Height = 38,
  127. ForeColor = Text,
  128. Font = new Font("Segoe UI Semibold", 20F, FontStyle.Regular)
  129. };
  130. panel.Controls.Add(valueLabel);
  131. panel.Controls.Add(titleLabel);
  132. if (!string.IsNullOrWhiteSpace(subtitle))
  133. {
  134. var subtitleLabel = new Label
  135. {
  136. Text = subtitle,
  137. Dock = DockStyle.Bottom,
  138. Height = 18,
  139. ForeColor = Muted,
  140. Font = new Font("Segoe UI", 8.5F, FontStyle.Regular)
  141. };
  142. panel.Controls.Add(subtitleLabel);
  143. }
  144. return panel;
  145. }
  146. public static GroupBox CreateSection(string title)
  147. {
  148. return new GroupBox
  149. {
  150. Text = title,
  151. Dock = DockStyle.Fill,
  152. Padding = new Padding(12),
  153. ForeColor = Text,
  154. Font = new Font("Segoe UI Semibold", 10F, FontStyle.Regular)
  155. };
  156. }
  157. public static PictureBox CreatePictureBox(Image image, Size size)
  158. {
  159. return new PictureBox
  160. {
  161. Image = image,
  162. SizeMode = PictureBoxSizeMode.Zoom,
  163. Size = size,
  164. BackColor = Color.Transparent
  165. };
  166. }
  167. public static Panel CreateHeaderPanel(string title, string subtitle)
  168. {
  169. var panel = new Panel
  170. {
  171. Height = 86,
  172. Dock = DockStyle.Top,
  173. BackColor = Surface,
  174. Padding = new Padding(20, 16, 20, 16),
  175. Margin = new Padding(0, 0, 0, 10),
  176. BorderStyle = BorderStyle.FixedSingle
  177. };
  178. var titleLabel = new Label
  179. {
  180. Text = title,
  181. Dock = DockStyle.Top,
  182. Height = 30,
  183. Font = new Font("Segoe UI Semibold", 18F, FontStyle.Regular),
  184. ForeColor = Text
  185. };
  186. var subtitleLabel = new Label
  187. {
  188. Text = subtitle,
  189. Dock = DockStyle.Fill,
  190. Font = new Font("Segoe UI", 9.5F, FontStyle.Regular),
  191. ForeColor = Muted
  192. };
  193. panel.Controls.Add(subtitleLabel);
  194. panel.Controls.Add(titleLabel);
  195. return panel;
  196. }
  197. public static Image? LoadImage(string fileName)
  198. {
  199. var candidates = new[]
  200. {
  201. Path.Combine(AppContext.BaseDirectory, "Assets", fileName),
  202. Path.Combine(Application.StartupPath, "Assets", fileName),
  203. Path.Combine(AppContext.BaseDirectory, fileName),
  204. Path.Combine(Directory.GetCurrentDirectory(), "Assets", fileName),
  205. Path.Combine(Directory.GetCurrentDirectory(), "TravelAgencyWinForms", "Assets", fileName)
  206. };
  207. foreach (var path in candidates)
  208. {
  209. if (!File.Exists(path))
  210. continue;
  211. using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  212. using var image = Image.FromStream(stream);
  213. return new Bitmap(image);
  214. }
  215. return null;
  216. }
  217. }