CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2007
    Posts
    122

    Error with GDI+ Sample

    Hi Guys,


    I am try to draw line and i want to make line rotate 360 degree and each degree changed regarding as timer intervals.


    Code:
      double x1, y1, r;
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                Graphics g = this.CreateGraphics();
                Pen p = new Pen(Color.Red);
                g.DrawEllipse(p, 0, 0, 398, 398);
                Pen p1 = new Pen(Color.Black);
    
    
    
                for (double theta = 20; r < 360; theta++)
                {
                    theta = theta * (Math.PI / 360);
                    x1 = r * (Math.Cos(theta));
                    y1 = r * (Math.Sin(theta));
                    g.DrawLine(p1, (float)x1, (float)y1, 200, 198);
                }
               
            }

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Error with GDI+ Sample

    You should not be doing all of the drawing inside of a loop in the paint event. That code will run very quickly and you won't see anything at all. Painting is an incremental process; for each tick of the time you should redraw the line once. So, store the last point on the edge of the circle externally from the paint method and increment it before calling Invalidate() once again. Each call to OnPaint() should be a single refresh, a single frame.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  3. #3
    Join Date
    Feb 2007
    Posts
    122

    Re: Error with GDI+ Sample

    I am try to do this change but error .......

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Error with GDI+ Sample

    What error? You could at least tell us what error you are encountering, we are not psychic.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured