bonjour besoin d'aide car la je ne vois pas ce qui va pas, mon code ne me mets pas d'erreur de compilation mais lorsque que je le lance, les lignes que je créé ne ce trace pas sur le coup mais ce trace qu'après que j'ai réduit la fenêtre donc voila mon code, merci d'avance et dites moi si pour la selection de la ligne mon code et juste au passage car je ne sui pas sur que cela soit juste !

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 public partial class Form1 : Form
    {
 
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Refresh();
        }
 
 
        public List<Line> line = new List<Line>();
        bool draw = false;
 
        public class Line
        {
            private Pen pen;
            public Point start;
            public Point end;
            public bool isSelected = false;
 
 
              public bool appartient(Point p)
              {
                  int a = 0;
                  if ((end.X - start.X) != 0)
                      a = (end.Y - start.Y) / (end.X - start.X);
 
                  int b = end.Y - (a * end.X);
 
                  if (((p.Y == (a * p.X + b))))
                  {
                      isSelected = true;
                      return true;
                  }
                  else
                  {
                      isSelected = false;
                      return false;
                  }
 
              }
 
              public Line(Pen pen, Point start, Point end)
              {
                  this.pen = pen;
                  this.start = start;
                  this.end = end;
              }
 
              public void OnPaint(Graphics g)
              {
                  g.DrawLine(new Pen(Brushes.Black), start, end);
                  //rectangle for line selection
                  if (isSelected)                                                 
                  {
                      g.FillRectangle(Brushes.Gray, new Rectangle(start, new Size(5, 5)));
                      g.DrawRectangle(pen, new Rectangle(start.X - 3, start.Y - 3, 6, 6));
                      g.FillRectangle(Brushes.Gray, new Rectangle(end, new Size(5, 5)));
                      g.DrawRectangle(pen, new Rectangle(end.X - 3, end.Y - 3, 6, 6));
                  }
              }
          }
 
            private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            {
                draw = true;
                line.Add(new Line(new Pen(Brushes.Blue), e.Location, e.Location));
                Invalidate();
            }
 
            private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (draw)
                {
                    line[line.Count - 1].end = e.Location;
                    Invalidate();
                    label1.Text = "souris enfonce";
                }
            }
 
            private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            {
                if (draw)
                {
                    line[line.Count - 1].end = e.Location;
                    draw = false;
                    label1.Text = "souris lache";
                }
            }
 
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                foreach (Line m in line)
                {
                    m.OnPaint(e.Graphics);
                    Invalidate();
                    label1.Text = "trace";
                }
            }
        }
 
 
 
 
    }