none
Como desenhar retas paralelas?

    Question

  • ola, fiz uma aplicação que ao clicar e arrastar o mouse desenha -se uma reta,

    com o ponto inicial onde o mouse down e ponto final onde mouse up.

    no entanto gostaria que alem dessa reta, ele desenhasse outra reta paralela a que ja é desenhada.

     

    private void panel1_MouseDown(object sender, MouseEventArgs e)
            {
                Drag = true;
                StartX = e.X;
                StartY = e.Y;
            }

    private void panel1_MouseUp(object sender, MouseEventArgs e)
            {
                Graphics g = panel1.CreateGraphics();
                Pen myPen = new Pen(Color.Aqua, 10);

                Drag = false;

                g.Clear(panel1.BackColor);
                g.DrawLine(myPen, StartX, StartY, e.X, e.Y);

                g.Dispose();
                myPen.Dispose();
            }

            private void panel1_MouseMove(object sender, MouseEventArgs e)
            {
                Graphics g = panel1.CreateGraphics();
                Pen myPen = new Pen(Color.Aqua, 10);

                CurrentX = e.X;
                CurrentY = e.Y;
                if (Drag == true)
                {
                    g.DrawLine(myPen, StartX, StartY, CurrentX, CurrentY);
                    CurrentX = e.X;
                    CurrentY = e.Y;
                }

                g.Dispose();
                myPen.Dispose();

    }

    Thursday, December 08, 2011 3:41 PM

Answers

  • Berg,

    Segue a solução:

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
                Graphics g = panel1.CreateGraphics();
                Pen myPen = new Pen(Color.Aqua, 20);
    
                Drag = false;
    
                g.Clear(panel1.BackColor);
    
                myPen.CompoundArray = new float[] { 0.0f, 0.4f, 0.6f, 1.0f };
    
                g.DrawLine(myPen, StartX, StartY, e.X, e.Y);
    
                g.Dispose();
                myPen.Dispose();
    }
    

    Abraço,


    Carlos Eduardo Ferreira
    Thursday, December 08, 2011 4:26 PM

All replies

  • Berg,

    Segue a solução:

    private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
                Graphics g = panel1.CreateGraphics();
                Pen myPen = new Pen(Color.Aqua, 20);
    
                Drag = false;
    
                g.Clear(panel1.BackColor);
    
                myPen.CompoundArray = new float[] { 0.0f, 0.4f, 0.6f, 1.0f };
    
                g.DrawLine(myPen, StartX, StartY, e.X, e.Y);
    
                g.Dispose();
                myPen.Dispose();
    }
    

    Abraço,


    Carlos Eduardo Ferreira
    Thursday, December 08, 2011 4:26 PM
  • perfeito cara!! muito obrigado..
    Monday, December 19, 2011 1:18 AM