fork download
  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.Windows.Forms;
  9. using System.Drawing.Drawing2D;
  10. using System.Drawing.Imaging;
  11.  
  12. namespace WindowsFormsApplication1
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. #region サンプルコード用
  21. Color[] _color = new Color[]
  22. {
  23. Color.Black,
  24. Color.Blue,
  25. Color.Red,
  26. Color.Green,
  27. Color.Gold,
  28. Color.Purple
  29. };
  30. LineCap[] _cap = new LineCap[]
  31. {
  32. LineCap.Flat,
  33. LineCap.Round,
  34. LineCap.Triangle,
  35. };
  36. DashStyle[] _style = new DashStyle[]
  37. {
  38. DashStyle.Solid,
  39. DashStyle.Dot,
  40. DashStyle.Dash,
  41. DashStyle.DashDot,
  42. DashStyle.DashDotDot
  43. };
  44. Random rnd = new Random();
  45. #endregion
  46.  
  47. const int cw = 640;
  48. const int ch = 480;
  49. Bitmap[] bmp = new Bitmap[2];
  50. int screen = 0;
  51. Layer _Layer = new Layer();
  52. PictureBox pictureBox1 = new PictureBox();
  53. ToolStrip toolStrip1 = new ToolStrip();
  54. ToolStripButton toolStripButton1 = new ToolStripButton();
  55. private void Form1_Load(object sender, EventArgs e)
  56. {
  57. this.Controls.Add(toolStrip1);
  58. this.Controls.Add(pictureBox1);
  59. pictureBox1.Dock = DockStyle.Fill;
  60. //toolStrip1.SendToBack();
  61. toolStrip1.Items.Add(toolStripButton1);
  62. toolStripButton1.Text = "Line";
  63. toolStripButton1.Click += new EventHandler(toolStripButton1_Click);
  64. bmp[0] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
  65. bmp[1] = new Bitmap(cw, ch, PixelFormat.Format32bppArgb);
  66. this.ScreenUpdate();
  67. }
  68. private void toolStripButton1_Click(object sender, EventArgs e)
  69. {
  70. Pen p = new Pen(_color[rnd.Next(0,_color.Length-1)]);
  71. p.Width = (float)rnd.Next(1, 20);
  72. p.StartCap = _cap[rnd.Next(0,_cap.Length-1)];
  73. p.EndCap = _cap[rnd.Next(0,_cap.Length-1)];
  74. p.DashStyle = _style[rnd.Next(0,_style.Length-1)];
  75. _Layer.AddLine(p,
  76. new PointF(
  77. (float)rnd.Next(20, cw-20),
  78. (float)rnd.Next(20, ch-20)),
  79. new PointF(
  80. (float)rnd.Next(20, cw-20),
  81. (float)rnd.Next(20, ch-20))
  82. );
  83. this.ScreenUpdate();
  84. }
  85. void ScreenUpdate()
  86. {
  87. using (Graphics g = Graphics.FromImage(bmp[screen]))
  88. {
  89. g.SmoothingMode = SmoothingMode.AntiAlias;
  90. g.FillRectangle(Brushes.White, 0, 0, cw, ch);
  91. _Layer.Draw(g);
  92. }
  93. pictureBox1.Image = bmp[screen];
  94. screen ^= 1;
  95. }
  96. }
  97. public class Layer
  98. {
  99. List<Shape> _Shapes = new List<Shape>();
  100. public Layer()
  101. {
  102. }
  103. public void AddLine(Pen p,PointF p1,PointF p2)
  104. {
  105. Shape s = new Shape();
  106. s.Pen = p;
  107. s.StartPoint = p1;
  108. s.EndPoint = p2;
  109. _Shapes.Add(s);
  110. }
  111. public void Draw(Graphics g)
  112. {
  113. foreach (Shape s in _Shapes)
  114. {
  115. switch (s.Type)
  116. {
  117. case 0:
  118. g.DrawLine(s.Pen, s.StartPoint, s.EndPoint);
  119. break;
  120. default:
  121. break;
  122. }
  123. }
  124. }
  125. }
  126. public class Shape
  127. {
  128. public int Type = 0;
  129. public Pen Pen;
  130. public PointF StartPoint;
  131. public PointF EndPoint;
  132. public Shape()
  133. {
  134. }
  135. }
  136. }
  137.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty