Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Flags
- {
- public partial class Flags : Form
- {
- enum Countries { Sudan = 1, Congo };
- Countries country;
- public Flags()
- {
- InitializeComponent();
- }
- private void Form1_Resize(object sender, EventArgs e)
- {
- Invalidate();
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- if (country == Countries.Sudan)
- DrawFlag_Sudan(ClientRectangle, e.Graphics);
- else if (country == Countries.Congo)
- DrawFlag_Congo(ClientRectangle, e.Graphics);
- }
- private void DrawFlag_Sudan(Rectangle r, Graphics g)
- {
- const int prop_x = 1, prop_y = 2;
- int H = r.Height - menuStrip1.Height, W = r.Width;
- Point WN = new Point(0, menuStrip1.Height);
- if (prop_x * r.Width > prop_y * r.Height)
- {
- W = H * prop_y / prop_x;
- WN.X = (r.Width - W) / 2;
- }
- else if (prop_x * r.Width < prop_y * r.Height)
- {
- H = W * prop_x / prop_y;
- WN.Y = (r.Height - H) / 2;
- }
- SolidBrush brush = new SolidBrush(Color.Black);
- g.FillRectangle(brush, WN.X, WN.Y, W, H);
- Point a = new Point(WN.X, WN.Y + H / 3);
- Point b = new Point(WN.X + W, WN.Y + H / 3);
- Point c = new Point(WN.X, WN.Y + 2 * H / 3);
- Point d = new Point(WN.X + W, WN.Y + 2 * H / 3);
- Point CenterL = new Point(WN.X, WN.Y + H / 2);
- Point CenterR = new Point(WN.X + W, WN.Y + H / 2);
- Point BottomL = new Point(WN.X, WN.Y + 6 * H / 7);
- Point BottomR = new Point(WN.X + W, WN.Y + 6 * H / 7);
- Pen pen = new Pen(Color.White, W / 38);
- g.DrawLine(pen, a, b);
- g.DrawLine(pen, c, d);
- pen.Color = System.Drawing.ColorTranslator.FromHtml("#da121a");
- pen.Width = W / 7;
- g.DrawLine(pen, CenterL, CenterR);
- pen.Color = System.Drawing.ColorTranslator.FromHtml("#078930");
- pen.Width = W / 6;
- g.DrawLine(pen, BottomL, BottomR);
- Point Center = new Point(WN.X + 2 * W / 5, WN.Y + H / 2);
- Point LeftBottom = new Point(WN.X, WN.Y + H);
- Point[] fillpoints = { WN, Center, LeftBottom };
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#0f47af");
- g.FillPolygon(brush, fillpoints);
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
- g.FillPolygon(brush, Draw_Star(WN.X + W / 7, WN.Y + H / 2, W / 12, H / 16, 0));
- Font font = new Font("Underlined", W / 71, FontStyle.Underline);
- StringFormat drawFormat = new System.Drawing.StringFormat();
- g.DrawString("Южный Судан", font, brush, WN.X + 3 * W / 4, WN.Y + H / 18, drawFormat);
- pen.Dispose();
- brush.Dispose();
- }
- private void DrawFlag_Congo(Rectangle r, Graphics g)
- {
- const int prop_x = 3, prop_y = 4;
- int H = r.Height - menuStrip1.Height, W = r.Width;
- Point WN = new Point(0, menuStrip1.Height);
- if (prop_x * r.Width > prop_y * r.Height)
- {
- W = H * prop_y / prop_x;
- WN.X = (r.Width - W) / 2;
- }
- else if (prop_x * r.Width < prop_y * r.Height)
- {
- H = W * prop_x / prop_y;
- WN.Y = (r.Height - H) / 2;
- }
- SolidBrush brush = new SolidBrush(Color.Blue);
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#007fff");
- g.FillRectangle(brush, WN.X, WN.Y, W, H);
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
- Point a = new Point(WN.X, WN.Y + 4 * H / 5);
- Point b = new Point(WN.X, WN.Y + H);
- Point c = new Point(WN.X + W / 17, WN.Y + H);
- Point d = new Point(WN.X + W, WN.Y + H / 5);
- Point e = new Point(WN.X + W, WN.Y);
- Point f = new Point(WN.X + 19 * W / 20, WN.Y);
- Point[] fillpoints1 = { a, b, c, d, e, f };
- g.FillPolygon(brush, fillpoints1);
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#ce1021");
- Point r1 = new Point(WN.X, WN.Y + 21 * H / 25);
- Point r2 = new Point(WN.X + W, WN.Y + 4 * H / 25);
- Point[] fillpoints2 = { r1, b, r2, e };
- g.FillPolygon(brush, fillpoints2);
- brush.Color = System.Drawing.ColorTranslator.FromHtml("#f7d618");
- g.FillPolygon(brush, Draw_Star(WN.X + W / 6, WN.Y + H / 3, W / 7.2, H / 14.5, 4.084));
- Font font = new Font("Underlined", W / 50, FontStyle.Underline);
- StringFormat drawFormat = new System.Drawing.StringFormat();
- g.DrawString("Демократическая Республика Конго", font,
- brush, WN.X + W / 3, WN.Y + H / 18, drawFormat);
- brush.Dispose();
- }
- private PointF[] Draw_Star(double center_x, double center_y, double R, double r, double alpha)
- {
- int num = 5;
- PointF[] points = new PointF[2 * num + 1];
- double a = Math.PI / num, rads;
- for (int i = 0; i < 2 * num + 1; i++)
- {
- rads = (i % 2 == 0) ? r : R;
- points[i] = new PointF((float)(center_x + rads * Math.Cos(alpha)),
- (float)(center_y + rads * Math.Sin(alpha)));
- alpha += a;
- }
- return points;
- }
- private void SudanMenu_Click(object sender, EventArgs e)
- {
- country = Countries.Sudan;
- Invalidate();
- }
- private void CongoMenu_Click(object sender, EventArgs e)
- {
- country = Countries.Congo;
- Invalidate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement