Form1.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace SimpleZeichenfunktion
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. int x = 0;
  20. int y = 0;
  21. //List<PointF> points = new List<PointF> { };
  22. //PointF init = new PointF(10, 10);
  23. PointF[] points = new PointF[10];
  24. int i = 0;
  25. PointF first;
  26. PointF second;
  27. bool clicked = false;
  28. PointF p;// = new PointF(x, y);
  29. private void Form1_MouseClick(object sender, MouseEventArgs e)
  30. {
  31. //points[0] = init;
  32. // label1.Text = "X=" + e.X + " Y=" + e.Y;
  33. /*
  34. x = e.X;
  35. y = e.Y;
  36. PointF p = new PointF(x, y);
  37. addPath(p);
  38. i++;
  39. */
  40. timer1.Enabled = !clicked;
  41. clicked = !clicked;
  42. }
  43. private void Form1_MouseMove(object sender, MouseEventArgs e)
  44. {
  45. x = e.X;
  46. y = e.Y;
  47. p = new PointF(x, y);
  48. /* if (clicked)
  49. {
  50. addPath(p);
  51. i++;
  52. }*/
  53. }
  54. public void addPath(PointF p)
  55. {
  56. // listBox1.Items.Add(p);
  57. //Aus den gegebenen Punkten eine Grafik erstellen
  58. points[i] = p;
  59. listBox1.Items.Add(points[i]);
  60. Pen pen = new Pen(Color.Black);
  61. Graphics g = CreateGraphics();
  62. first = points[0];
  63. if (i == 1)
  64. {
  65. second = points[1];
  66. g.DrawLine(pen, first, second);
  67. points[0] = second;
  68. i = 0;
  69. }
  70. }
  71. private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
  72. {
  73. //Do Nothing
  74. }
  75. private void timer1_Tick(object sender, EventArgs e)
  76. {
  77. timer1.Interval = 100;
  78. if (clicked)
  79. {
  80. addPath(p);
  81. i++;
  82. }
  83. }
  84. }
  85. }