Click here to Skip to main content
15,887,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: Painting on transparent background multiple times Pin
Abhishek Sur12-Sep-10 2:39
professionalAbhishek Sur12-Sep-10 2:39 
GeneralRe: Painting on transparent background multiple times Pin
fdsfsa76f7sa612-Sep-10 3:06
fdsfsa76f7sa612-Sep-10 3:06 
GeneralRe: Painting on transparent background multiple times Pin
Dave Kreskowiak12-Sep-10 5:13
mveDave Kreskowiak12-Sep-10 5:13 
GeneralRe: Painting on transparent background multiple times Pin
fdsfsa76f7sa612-Sep-10 8:49
fdsfsa76f7sa612-Sep-10 8:49 
AnswerRe: Painting on transparent background multiple times Pin
Luc Pattyn12-Sep-10 9:39
sitebuilderLuc Pattyn12-Sep-10 9:39 
GeneralRe: Painting on transparent background multiple times Pin
fdsfsa76f7sa612-Sep-10 10:50
fdsfsa76f7sa612-Sep-10 10:50 
GeneralRe: Painting on transparent background multiple times Pin
Luc Pattyn12-Sep-10 10:56
sitebuilderLuc Pattyn12-Sep-10 10:56 
Questionhow to call onPaint from Timer Pin
bimbambumbum11-Sep-10 19:13
bimbambumbum11-Sep-10 19:13 
Hi
I'm trying to work my way into the world of .NET programming so this question might be a no-brainer.


I'm trying to make a timer-control redrawing GDI graphics so that the GUI gets updated at regular time intervals.

The overrided OnPaint() is currently doing the drawing and it should be called from the timer_tick() method. Please take a look at the code below.

I looked for an onPaint() redraw/update method but couldn't find such one.

Can someone please give me a hint?

Thanks
Tom

public partial class Form1 : Form
 {
     Timer timer = new Timer();
     Graphics g;
     int x2 = 100;   // the end  location of the line being drawn
     int y2 = 100;   // the end  location of the line being drawn

     public Form1()
     {
         InitializeComponent();

         timer.Tick += new EventHandler(timer_tick);
         timer.Interval = 1000;      // update graphics every sec!!
         timer.Enabled = true;
         timer.Start();

     }

     void timer_tick(object sender, EventArgs e)
     {
         //MessageBox.Show("Tick");                    // Alert the user
     }

     private void Form1_Paint(object sender, PaintEventArgs e)
     {
     }

     protected override void OnPaint(PaintEventArgs pe)
     {
         g = pe.Graphics;

         // Draw coordinate system
         Pen pn = new Pen(Color.Black, 1);
         Point pt1 = new Point(0, 0);
         Point pt2 = new Point(x2, y2++);
         g.DrawLine(pn, pt1, pt2);

         if (y2 > 300)
             y2 = 100;       // increment y-coordinate to see that onPaint gets called from timer

     }

AnswerRe: how to call onPaint from Timer Pin
Abhinav S11-Sep-10 19:35
Abhinav S11-Sep-10 19:35 
GeneralRe: how to call onPaint from Timer Pin
bimbambumbum11-Sep-10 19:40
bimbambumbum11-Sep-10 19:40 
GeneralRe: how to call onPaint from Timer Pin
Thomas Stockwell12-Sep-10 8:29
professionalThomas Stockwell12-Sep-10 8:29 
Questioncustom titlebar Pin
Jassim Rahma11-Sep-10 7:31
Jassim Rahma11-Sep-10 7:31 
AnswerRe: custom titlebar Pin
Abhishek Sur11-Sep-10 10:50
professionalAbhishek Sur11-Sep-10 10:50 
AnswerRe: custom titlebar Pin
Ravi Bhavnani11-Sep-10 15:41
professionalRavi Bhavnani11-Sep-10 15:41 
AnswerRe: custom titlebar Pin
Abhinav S11-Sep-10 21:25
Abhinav S11-Sep-10 21:25 
AnswerRe: custom titlebar Pin
Thomas Stockwell12-Sep-10 8:30
professionalThomas Stockwell12-Sep-10 8:30 
QuestionMessage Removed Pin
11-Sep-10 3:08
arkiboys11-Sep-10 3:08 
AnswerRe: Calculation Pin
Richard MacCutchan11-Sep-10 3:31
mveRichard MacCutchan11-Sep-10 3:31 
AnswerRe: Calculation Pin
harold aptroot11-Sep-10 3:34
harold aptroot11-Sep-10 3:34 
GeneralMessage Removed Pin
11-Sep-10 3:36
arkiboys11-Sep-10 3:36 
GeneralRe: Calculation Pin
PIEBALDconsult11-Sep-10 4:03
mvePIEBALDconsult11-Sep-10 4:03 
GeneralRe: Calculation Pin
Luc Pattyn11-Sep-10 4:06
sitebuilderLuc Pattyn11-Sep-10 4:06 
GeneralMessage Removed Pin
11-Sep-10 4:06
arkiboys11-Sep-10 4:06 
GeneralRe: Calculation Pin
harold aptroot11-Sep-10 4:12
harold aptroot11-Sep-10 4:12 
GeneralRe: Calculation Pin
PIEBALDconsult11-Sep-10 4:13
mvePIEBALDconsult11-Sep-10 4:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.