int toto = Convert.ToInt32("1"); int tutu = int.Parse("2");
int x1 = -1; int y1 = -1; int x2 = -1; int y2 = -1; private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (x1 == -1) { x1 = e.X; y1 = e.Y; } else { x2 = e.X; y2 = e.Y; } } public void DrawLineInt(PaintEventArgs e) { Pen blackPen = new Pen(Color.Red, 3); //ici ton code pour déssiner la ligne //réinit des valeurs x1 = -1; y1 = -1; x2 = -1; y2 = -1; }
using System.Drawing; namespace Test_Winform { class Segment { public Point Point1 { get; set; } public Point Point1 { get; set; } public Color Couleur { get; set; } } }
List<Segment> segments = new List<Segment>(); private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen blackPen; //Lignes précendentes foreach (Segment s in segments) { blackPen = new Pen(s.Couleur, 3); e.Graphics.DrawLine(blackPen,s.Point1,s.Point2); } //Gestion de la ligne en cours blackPen = new Pen(Color.Red, 3); if (x1 != -1) { e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); if (fin2ligne) { //enregistre la ligne segments.Add(new Segment(x1, y1, x2, y2, Color.Blue)); //réinit des valeurs x1 = -1; y1 = -1; x2 = -1; y2 = -1; } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpublic void DrawLineInt(PaintEventArgs e) { Pen blackPen = new Pen(Color.Red, 3); int x1 = a1; int y1 = a2; int x2 = b1; int y2 = b2; } string a1, a2, b1, b2; private void pictureBox_MouseDown(object sender, MouseEventArgs e) { // Récupération de la position de départ a1 = e.X.ToString(); a2 = e.Y.ToString(); } private void pictureBox_MouseUp(object sender, MouseEventArgs e) { // Récupération de la position d'arrivée b1 = e.X.ToString(); b2 = e.Y.ToString(); }
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2);
int x1 = -1; int y1 = -1; int x2 = -1; int y2 = -1; private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (x1 == -1) { x1 = e.X; y1 = e.Y; } else { x2 = e.X; y2 = e.Y; pictureBox1.Refresh(); } } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen blackPen = new Pen(Color.Red, 3); e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); //réinit des valeurs x1 = -1; y1 = -1; x2 = -1; y2 = -1; }
int x1 = -1; int y1 = -1; int x2 = -1; int y2 = -1; bool fin2ligne = false; private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (x1 == -1) { x1 = e.X; y1 = e.Y; } else { x2 = e.X; y2 = e.Y; fin2ligne = true; pictureBox1.Refresh(); } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (x1 == -1) return; x2 = e.X; y2 = e.Y; fin2ligne = false; pictureBox1.Refresh(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen blackPen = new Pen(Color.Red, 3); if (x1 != -1) { e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); if (fin2ligne) { //réinit des valeurs x1 = -1; y1 = -1; x2 = -1; y2 = -1; } } }
public Form1() { InitializeComponent(); } int x1 = -1; int y1 = -1; int x2 = -1; int y2 = -1; bool fin2ligne = false; class Segment { public Point Point1 { get; set; } public Point Point2 { get; set; } public Color Couleur { get; set; } } List<Segment> segments = new List<Segment>(); private void pictureBox1_Paint(object sender, PaintEventArgs e) { Pen blackPen; //Lignes précédentes foreach (Segment s in segments) { blackPen = new Pen(s.Couleur, 3); e.Graphics.DrawLine(blackPen, s.Point1, s.Point2); } //Gestion de la ligne en cours blackPen = new Pen(Color.Red, 3); if (x1 != -1) { e.Graphics.DrawLine(blackPen, x1, y1, x2, y2); if (fin2ligne) { //enregistre la ligne segments.Add(new Segment(x1, y1, x2, y2, Color.Blue)); //réinitialisation des valeurs x1 = -1; y1 = -1; x2 = -1; y2 = -1; } } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (x1 == -1) return; x2 = e.X; y2 = e.Y; fin2ligne = false; pictureBox1.Refresh(); } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (x1 == -1) { x1 = e.X; y1 = e.Y; } else { x2 = e.X; y2 = e.Y; fin2ligne = true; pictureBox1.Refresh(); } }
using System.Drawing; namespace Test_Winform { class Segment { public Segment(int X1, int Y1, int X2, int Y2, Color Couleur) { Point1 = new Point(X1, Y1); Point2 = new Point(X2, Y2); this.Couleur = Couleur; } public Point Point1 { get; set; } public Point Point2 { get; set; } public Color Couleur { get; set; } } }