Draw lines C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hastalavista
    New Member
    • May 2007
    • 2

    #1

    Draw lines C#

    HI

    I'm very new to C# and I've got a big project to do in C# for uni until july.

    I've been trying do draw lines in C# (arrows to be precise). I can draw them allright but once I minimize the program and maximize it again, the arrows dissapear :S.
    this also happens if I open another program on top of the program I'm creating.
    Is their a way to correct this?

    To draw the lines I've been using this piece of code.
    Code:
                   
     Graphics graph =  panel1.CreateGraphics();  
     Pen pencurrent = new Pen(Color.Black);  
     graph.DrawLine(pencurrent, 220, ultimoponto, 220, ultimoponto+20);
     graph.DrawLine(pencurrent, 215, ultimoponto + 15, 220, ultimoponto+20);
     graph.DrawLine(pencurrent, 225, ultimoponto + 15, 220, ultimoponto+20);
    thanks in advance.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Is there any event is triggered by maximizing the program?

    Comment

    • hastalavista
      New Member
      • May 2007
      • 2

      #3
      nope. no events.
      The minimzing and maximizing was an example. this also happens if I move another window on top of the arrow. (I'm not sure if I'm making myself clear). When the arrow is hidden due to the program being minimized, or due to being hidden by another window, it simply dissapears.

      Comment

      • vanc
        Recognized Expert New Member
        • Mar 2007
        • 211

        #4
        try to refresh your panel

        cheers.

        Comment

        • shidec
          New Member
          • May 2007
          • 26

          #5
          Put ur program at OnPaint event of the panel,
          so every time its need to redraw it will do.

          Try to find graphic/animation program in c#,
          they always override OnPaint method on a class.

          [CODE=vbnet]
          using System;
          using System.Collecti ons.Generic;
          using System.Componen tModel;
          using System.Data;
          using System.Drawing;
          using System.Text;
          using System.Windows. Forms;

          namespace TryDraw
          {
          public partial class Form1 : Form
          {
          public Form1()
          {
          InitializeCompo nent();
          }

          private void panel1_Paint(ob ject sender, PaintEventArgs e)
          {
          int ultimoponto = 100;
          Pen pencurrent = new Pen(Color.Black );
          e.Graphics.Draw Line(pencurrent , 220, ultimoponto, 220, ultimoponto+20) ;
          e.Graphics.Draw Line(pencurrent , 215, ultimoponto + 15, 220, ultimoponto + 20);
          e.Graphics.Draw Line(pencurrent , 225, ultimoponto + 15, 220, ultimoponto + 20);
          }
          }
          }
          [/CODE]

          Comment

          Working...