469,352 Members | 1,794 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

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.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  Graphics graph =  panel1.CreateGraphics();  
  3.  Pen pencurrent = new Pen(Color.Black);  
  4.  graph.DrawLine(pencurrent, 220, ultimoponto, 220, ultimoponto+20);
  5.  graph.DrawLine(pencurrent, 215, ultimoponto + 15, 220, ultimoponto+20);
  6.  graph.DrawLine(pencurrent, 225, ultimoponto + 15, 220, ultimoponto+20);
  7.  
thanks in advance.
May 20 '07 #1
4 8968
kenobewan
4,871 Expert 4TB
Is there any event is triggered by maximizing the program?
May 20 '07 #2
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.
May 20 '07 #3
vanc
211 Expert 100+
try to refresh your panel

cheers.
May 20 '07 #4
shidec
26
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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace TryDraw
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.  
  18.         private void panel1_Paint(object sender, PaintEventArgs e)
  19.         {
  20.             int ultimoponto = 100;
  21.             Pen pencurrent = new Pen(Color.Black); 
  22.             e.Graphics.DrawLine(pencurrent, 220, ultimoponto, 220, ultimoponto+20);
  23.             e.Graphics.DrawLine(pencurrent, 215, ultimoponto + 15, 220, ultimoponto + 20);
  24.             e.Graphics.DrawLine(pencurrent, 225, ultimoponto + 15, 220, ultimoponto + 20);
  25.         }
  26.     }
  27. }
  28.  
May 21 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by prakash437 | last post: by
6 posts views Thread by Nirosh | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.