Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Flags
  12. {
  13. public partial class Flags : Form
  14. {
  15. enum Countries { Sudan = 1, Congo };
  16. Countries country;
  17.  
  18. public Flags()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void Form1_Resize(object sender, EventArgs e)
  24. {
  25. Invalidate();
  26. }
  27.  
  28. protected override void OnPaint(PaintEventArgs e)
  29. {
  30. base.OnPaint(e);
  31. if (country == Countries.Sudan)
  32. DrawFlag_Sudan(ClientRectangle, e.Graphics);
  33. else if (country == Countries.Congo)
  34. DrawFlag_Congo(ClientRectangle, e.Graphics);
  35. }
  36.  
  37. private void DrawFlag_Sudan(Rectangle r, Graphics g)
  38. {
  39. const int prop_x = 1, prop_y = 2;
  40. int H = r.Height - menuStrip1.Height, W = r.Width;
  41. Point WN = new Point(0, menuStrip1.Height);
  42.  
  43. if (prop_x * r.Width > prop_y * r.Height)
  44. {
  45. W = H * prop_y / prop_x;
  46. WN.X = (r.Width - W) / 2;
  47. }
  48.  
  49. else if (prop_x * r.Width < prop_y * r.Height)
  50. {
  51. H = W * prop_x / prop_y;
  52. WN.Y = (r.Height - H) / 2;
  53. }
  54.  
  55. SolidBrush brush = new SolidBrush(Color.Black);
  56. g.FillRectangle(brush, WN.X, WN.Y, W, H);
  57. Point a = new Point(WN.X, WN.Y + H / 3);
  58. Point b = new Point(WN.X + W, WN.Y + H / 3);
  59. Point c = new Point(WN.X, WN.Y + 2 * H / 3);
  60. Point d = new Point(WN.X + W, WN.Y + 2 * H / 3);
  61. Point CenterL = new Point(WN.X, WN.Y + H / 2);
  62. Point CenterR = new Point(WN.X + W, WN.Y + H / 2);
  63. Point BottomL = new Point(WN.X, WN.Y + 6 * H / 7);
  64. Point BottomR = new Point(WN.X + W, WN.Y + 6 * H / 7);
  65.  
  66. Pen pen = new Pen(Color.White, W / 38);
  67. g.DrawLine(pen, a, b);
  68. g.DrawLine(pen, c, d);
  69. pen.Color = System.Drawing.ColorTranslator.FromHtml("#da121a");
  70. pen.Width = W / 7;
  71. g.DrawLine(pen, CenterL, CenterR);
  72. pen.Color = System.Drawing.ColorTranslator.FromHtml("#078930");
  73. pen.Width = W / 6;
  74. g.DrawLine(pen, BottomL, BottomR);
  75.  
  76. Point Center = new Point(WN.X + 2 * W / 5, WN.Y + H / 2);
  77. Point LeftBottom = new Point(WN.X, WN.Y + H);
  78. Point[] fillpoints = { WN, Center, LeftBottom };
  79. brush.Color = System.Drawing.ColorTranslator.FromHtml("#0f47af");
  80. g.FillPolygon(brush, fillpoints);
  81. brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
  82. g.FillPolygon(brush, Draw_Star(WN.X + W / 7, WN.Y + H / 2, W / 12, H / 16, 0));
  83.  
  84. Font font = new Font("Underlined", W / 71, FontStyle.Underline);
  85. StringFormat drawFormat = new System.Drawing.StringFormat();
  86. g.DrawString("Южный Судан", font, brush, WN.X + 3 * W / 4, WN.Y + H / 18, drawFormat);
  87.  
  88. pen.Dispose();
  89. brush.Dispose();
  90. }
  91.  
  92. private void DrawFlag_Congo(Rectangle r, Graphics g)
  93. {
  94. const int prop_x = 3, prop_y = 4;
  95. int H = r.Height - menuStrip1.Height, W = r.Width;
  96. Point WN = new Point(0, menuStrip1.Height);
  97.  
  98. if (prop_x * r.Width > prop_y * r.Height)
  99. {
  100. W = H * prop_y / prop_x;
  101. WN.X = (r.Width - W) / 2;
  102. }
  103.  
  104. else if (prop_x * r.Width < prop_y * r.Height)
  105. {
  106. H = W * prop_x / prop_y;
  107. WN.Y = (r.Height - H) / 2;
  108. }
  109.  
  110. SolidBrush brush = new SolidBrush(Color.Blue);
  111. brush.Color = System.Drawing.ColorTranslator.FromHtml("#007fff");
  112. g.FillRectangle(brush, WN.X, WN.Y, W, H);
  113. brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
  114. Point a = new Point(WN.X, WN.Y + 4 * H / 5);
  115. Point b = new Point(WN.X, WN.Y + H);
  116. Point c = new Point(WN.X + W / 17, WN.Y + H);
  117. Point d = new Point(WN.X + W, WN.Y + H / 5);
  118. Point e = new Point(WN.X + W, WN.Y);
  119. Point f = new Point(WN.X + 19 * W / 20, WN.Y);
  120. Point[] fillpoints1 = { a, b, c, d, e, f };
  121. g.FillPolygon(brush, fillpoints1);
  122.  
  123. brush.Color = System.Drawing.ColorTranslator.FromHtml("#ce1021");
  124. Point r1 = new Point(WN.X, WN.Y + 21 * H / 25);
  125. Point r2 = new Point(WN.X + W, WN.Y + 4 * H / 25);
  126. Point[] fillpoints2 = { r1, b, r2, e };
  127. g.FillPolygon(brush, fillpoints2);
  128. brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
  129. g.FillPolygon(brush, Draw_Star(WN.X + W / 6, WN.Y + H / 3, W / 7.2, H / 14.5, 4.084));
  130.  
  131. Font font = new Font("Underlined", W / 50, FontStyle.Underline);
  132. StringFormat drawFormat = new System.Drawing.StringFormat();
  133. g.DrawString("Демократическая Республика Конго", font,
  134. brush, WN.X + W / 3, WN.Y + H / 18, drawFormat);
  135. brush.Dispose();
  136. }
  137.  
  138. private PointF[] Draw_Star(double center_x, double center_y, double R, double r, double alpha)
  139. {
  140. int num = 5;
  141. PointF[] points = new PointF[2 * num + 1];
  142. double a = Math.PI / num, rads;
  143. for (int i = 0; i < 2 * num + 1; i++)
  144. {
  145. rads = (i % 2 == 0) ? r : R;
  146. points[i] = new PointF((float)(center_x + rads * Math.Cos(alpha)),
  147. (float)(center_y + rads * Math.Sin(alpha)));
  148. alpha += a;
  149. }
  150. return points;
  151. }
  152.  
  153. private void SudanMenu_Click(object sender, EventArgs e)
  154. {
  155. country = Countries.Sudan;
  156. Invalidate();
  157. }
  158.  
  159. private void CongoMenu_Click(object sender, EventArgs e)
  160. {
  161. country = Countries.Congo;
  162. Invalidate();
  163. }
  164. }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement