locked
How to paint without Control.Paint? RRS feed

  • Question

  • I use:

    panels[i].Paint += Method;

    But when it gets painted by Timer Class it gets done very fast, i. e. it invokes "Method" every time.

    How to draw easier?

    • Moved by CoolDadTx Wednesday, August 20, 2014 1:48 PM Winforms related
    Monday, August 18, 2014 2:48 PM

Answers

  • On my computer it appears and suddenly gets much more bigger and then starts getting bigger once per second just like what I had.

    A circle should appear at minimal size 0 and get bigger.

    I captured a video of the problem using my code and your code.

    http://youtu.be/pvzD09u31UU

    Did you try with my code suggestion?  It should fix what you see.

    It's a small change to your code.  I'll post my changes again just so you know which code I'm talking about.  Just replace your Game_Continue_Invalidate and Game_Continue functions with these:

    private void Game_Continue_Invalidate( object sender, EventArgs e )
    {
        for( int i = 0; i < this.i; i++ ) {
            panels[i].Width++;
            panels[i].Height++;
            panels[i].Invalidate();
        }
    }
    
    private void Game_Continue( object sender, PaintEventArgs e )
    {
        e.Graphics.Clear( Color.White );
    
        e.Graphics.DrawEllipse( pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1 );
    }
     

    Again, the point here is to change where you were doing Width++ and Height++.

    You might also want it to update more frequently than once per second.  1000ms is a pretty slow interval for animation  that's only 1 fps.  You might try an interval of 50ms.  That would be 20 fps.  (1000ms / 50ms = 20fps)

    • Marked as answer by Ziya Ceferov Thursday, August 21, 2014 6:10 AM
    Thursday, August 21, 2014 1:26 AM

All replies

  • That looks pretty easy to me.

    Have your timer method call Refresh if you're trying to do animation.  or Invalidate() if it's expected to idle for a bit in between updates.

    I don't understand what you dislike about this technique.  Can you explain what you mean by "it gets done very fast"?  That sounds like a good thing to me.

    Monday, August 18, 2014 3:13 PM
  • That looks pretty easy to me.

    Have your timer method call Refresh if you're trying to do animation.  or Invalidate() if it's expected to idle for a bit in between updates.

    I don't understand what you dislike about this technique.  Can you explain what you mean by "it gets done very fast"?  That sounds like a good thing to me.

    Timer draws on a panel by interval, while the next code gets invoked making it faster:

    panels[i].Paint += Method;

    I think it is easy, can you give an example code and explain how to use Bitmap Class and Invalidate() in such cases?



    Monday, August 18, 2014 3:31 PM
  • Timer draws on a panel by interval, while the next code gets invoked making it faster:

    panels[i].Paint += Method;

    I think one of us misunderstands something.  Invoke to me means something very specific, and has to do with dispatching a call to a different thread.  I think you just mean call.

    Here's an analog clock example that updates once per second using a timer.  Does this help?

    public partial class Form1 : Form
    {
        Timer timer;
        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
            this.Paint += Form1_Paint;
            this.Resize += delegate { Invalidate(); };
            timer = new Timer();
            timer.Interval = 1000;
            timer.Tick += timer_Tick;
            timer.Enabled = true;
        }
    
        void timer_Tick( object sender, EventArgs e )
        {
            this.Invalidate();
        }
    
        void Form1_Paint( object sender, PaintEventArgs e )
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    
            e.Graphics.Clear( Color.White );
    
            float cx = ClientSize.Width / 2.0f;
            float cy = ClientSize.Height / 2.0f;
            float r = cx;
            if( cx > cy ) {
                r = cy;
            }
    
            double angle, sin, cos;
            for( int i = 0; i < 12; i++ ) {
                angle = i / 12.0 * Math.PI * 2.0;
                sin = Math.Sin( angle );
                cos = Math.Cos( angle );
                e.Graphics.DrawLine( Pens.Gray, (float)(cx + r * 0.9 * sin), (float)(cy - r * 0.9 * cos), (float)(cx + r * sin), (float)(cy - r * cos) );
            }
            angle = DateTime.Now.Second / 60.0 * Math.PI * 2.0;
            sin = Math.Sin( angle );
            cos = Math.Cos( angle );
            e.Graphics.DrawLine( Pens.Red, cx, cy, (float)(cx + r * sin), (float)(cy - r * cos) );
            angle = (DateTime.Now.Minute * 60 + DateTime.Now.Second) / (60.0*60.0) * Math.PI * 2.0;
            sin = Math.Sin( angle );
            cos = Math.Cos( angle );
            e.Graphics.DrawLine( Pens.Black, cx, cy, (float)(cx + r * sin), (float)(cy - r * cos) );
            angle = ((DateTime.Now.Hour%12) * 60.0 * 60.0 + DateTime.Now.Minute * 60 + DateTime.Now.Second) / (12.0*60.0*60.0) * Math.PI * 2.0;
            sin = Math.Sin( angle );
            cos = Math.Cos( angle );
            e.Graphics.DrawLine( Pens.Black, cx, cy, (float)(cx + r * 0.5 * sin), (float)(cy - r * 0.5 * cos) );
    
        }
    }
    

    Monday, August 18, 2014 6:49 PM
  • In my next code I wanna create circles that are getting bigger and bigger from the tiniest size.

    They are drawn on panels.

    Problem: they get called every time when they get drawn and it makes it faster.

    How to solve this problem?

            Timer timer_game = new Timer();
            Timer timer_continue = new Timer();
            Random r1 = new Random();
            public Pen pen;
            Panel[] panels;
            int i = 0;
            int length = 100;
    
            Graphics g;
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.DoubleBuffered = true;
    
                panels = new Panel[length];
                pen = new Pen(Color.Black);
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
    
                timer_continue.Interval = 1000;
                timer_continue.Enabled = true;
    
                timer_game.Interval = 1000;
                timer_game.Enabled = true;
                timer_game.Tick += Game_Start;
            }
    
            private void Game_Start(object sender, EventArgs e)
            {
                int i1 = r1.Next(0, this.Width);
                int i2 = r1.Next(0, this.Height);
    
                panels[i] = new Panel();
                panels[i].Parent = this;
                panels[i].BackColor = Color.White;
                panels[i].Location = new Point(i1, i2);
                panels[i].Width = 1;
                panels[i].Height = 1;
                panels[i].Paint += Game_Continue;
    
                if (i == 0) timer_continue.Tick += Game_Continue_Invalidate;
    
                i++;
            }
    
            private void Game_Continue_Invalidate(object sender, EventArgs e)
            {
                for (int i = 0; i < this.i; i++)
                    panels[i].Invalidate();
            }
    
            private void Game_Continue(object sender, PaintEventArgs e)
            {
                e.Graphics.Clear(Color.White);
    
                ((Panel)sender).Width++;
                ((Panel)sender).Height++;
                pen.Width = 1;
                e.Graphics.DrawEllipse(pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1);
            }
    }
    • Marked as answer by Ziya Ceferov Tuesday, August 19, 2014 6:18 AM
    • Unmarked as answer by Ziya Ceferov Tuesday, August 19, 2014 6:18 AM
    Tuesday, August 19, 2014 5:57 AM
  • In my next code I wanna create circles that are getting bigger and bigger from the tiniest size.

    They are drawn on panels.

    Problem: they get called every time when they get drawn and it makes it faster.

    How to solve this problem?

            Timer timer_game = new Timer();
            Timer timer_continue = new Timer();
            Random r1 = new Random();
            public Pen pen;
            Panel[] panels;
            int i = 0;
            int length = 100;
    
            Graphics g;
    
            private void button1_Click(object sender, EventArgs e)
            {
                this.DoubleBuffered = true;
    
                panels = new Panel[length];
                pen = new Pen(Color.Black);
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
    
                timer_continue.Interval = 1000;
                timer_continue.Enabled = true;
    
                timer_game.Interval = 1000;
                timer_game.Enabled = true;
                timer_game.Tick += Game_Start;
            }
    
            private void Game_Start(object sender, EventArgs e)
            {
                int i1 = r1.Next(0, this.Width);
                int i2 = r1.Next(0, this.Height);
    
                panels[i] = new Panel();
                panels[i].Parent = this;
                panels[i].BackColor = Color.White;
                panels[i].Location = new Point(i1, i2);
                panels[i].Width = 1;
                panels[i].Height = 1;
                panels[i].Paint += Game_Continue;
    
                if (i == 0) timer_continue.Tick += Game_Continue_Invalidate;
    
                i++;
            }
    
            private void Game_Continue_Invalidate(object sender, EventArgs e)
            {
                for (int i = 0; i < this.i; i++)
                    panels[i].Invalidate();
            }
    
            private void Game_Continue(object sender, PaintEventArgs e)
            {
                e.Graphics.Clear(Color.White);
    
                ((Panel)sender).Width++;
                ((Panel)sender).Height++;
                pen.Width = 1;
                e.Graphics.DrawEllipse(pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1);
            }
    }

    I still don't understand what you mean about "it gets faster", but I'll try to comment on what I observe.

    I think this all hinges on your misunderstanding of multicast delegates and adding event handlers with the += operator.  I suggest you read How to: Subscribe to and Unsubscribe from Events.  You only need to add the handler once.  If you add it multiple times, it will be called multiple times.  E.g.: If you add it 5 times (because you click the button 5 times), then each tick will call your handler 5 times.

    • Why so many panels?  Isn't one panel enough?  Why use a panel per shape?  Just have one panel that draws all your shapes.  I realize that you're using the framework to handle your hit-testing and such, but this will not scale well as you add objects.  And the redrawing and compositing will be ugly.
    • Why add a game tick handler every time you click button1?  Just add the event handler once in your constructor.  What is button1?  Is it a "start" button?  Does the problem come from clicking this button multiple times?  If so, then you may be executing your tick handler multiple times, because each time you click button1, you add the Game_Start handler to the multicast delegate again.  So that each time the Tick event is fired, the Game_Start handler will be called once per each time you've clicked button1.  I suspect this is your most significant problem.
    • Strange thing:  Tick calls Start?  You "start" once per tick?!?  Is this just bad naming or is this a logical error?  Did you really intend to create a new panel every second?  This is weird.
    • You have a paint handler called "Continue"?!?  Why not "Paint"?  There are strange naming conventions here.
    • Why are you trying to animate the objects themselves?  This might work in WPF, but it's going to be slow in Windows Forms.  The message passing and layout will be cumbersome as the number of objects grows.
    • Why make the panel bigger every time you paint?  What does that accomplish?  (Width++, Height++)  I think you are just using the panel to store the width and height of the circle and get the layout done for free. (Note, it's not free, it just takes place within the context of the framework.)
    • I would assume you want the circles to grow about their center, not their top left bounding box edge.  So it would be necessary to move the top and left as well as the width and height  (move the top and left up and left by one unit and the width and height down and right by two units to keep it centered.)

    Overall I suggest just having a single panel that draws everything.

    1. One panel to rule them all.
    2. Set .DoubleBuffered to true so that you get nice flicker-free drawing.
    3. Have a class per ellipse that remembers its position, radius, color, etc.
    4. Store a list of these Ellipse objects.
    5. In your paint handler for the panel, loop through all your ellipses and draw them.
    6. Your tick handler should simply update radius of each circle then Refresh the panel.

    To get better performance you'll have to go to WPF or D3D.

    I realize you're leveraging the framework to keep track of your ellipses for you by just stashing their data in a Panel object, but as your game grows, you'll eventually want a class per object anyway.  Might as well refactor now.

    Tuesday, August 19, 2014 1:57 PM
  • Listen, I just wanna make growing circles! This code is nothing! I will make it much more better if I solve this damn problem.

    I just need you to fix a few rows of the code. Please help, thank you.

    And of course a lot of thanks for the advices, i am going to use it.

    Just say how to solve this problem in MY code?

    Wait a minute, I have captured a video of the problem, you will understand it completely.

    Look:

    https://www.youtube.com/watch?v=D05GjbLLUYo

    Just look at how circles get bigger at a high speed.

    I know, my code is very bad, but how to solve so tiny problem?


    Tuesday, August 19, 2014 2:46 PM
  • I think this might help.

    private int ticksemaphore = 1;

    private int paintsemaphore = 1;

    void timer_Tick( object sender, EventArgs e )
       
    {

            if (--ticksemaphore >= 0)

            {
               
    this.Invalidate();

            }        ++ticksemaphore;
       
    }

       
    void Form1_Paint( object sender, PaintEventArgs e )
       
    {

            if (--paintsemaphore >= 0)

            {

                do etc...

            }

            ++paintsemaphore;

        }

    The point of this is to prevent multiple access.


    VP

    Tuesday, August 19, 2014 3:04 PM
  • You variant didn't help. That is my full code:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace _123
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            Timer timer_game = new Timer();
            Timer timer_continue = new Timer();
            Random r1 = new Random();
            public Pen pen;
            Panel[] panels;
            int i = 0;
            int length = 100;
    
            private void button1_Click(object sender, EventArgs e)
            {
                panels = new Panel[length];
                pen = new Pen(Color.Black);
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                pen.Width = 1;
    
                timer_continue.Interval = 1000;
                timer_continue.Enabled = true;
    
                timer_game.Interval = 1000;
                timer_game.Enabled = true;
                timer_game.Tick += Game_Start;
            }
    
            private void Game_Start(object sender, EventArgs e)
            {
                int i1 = r1.Next(0, this.Width);
                int i2 = r1.Next(0, this.Height);
    
                panels[i] = new Panel();
                panels[i].Parent = this;
                panels[i].BackColor = Color.White;
                panels[i].Location = new Point(i1, i2);
                panels[i].Width = 1;
                panels[i].Height = 1;
                panels[i].Paint += Game_Continue;
    
                if (i == 0)
                    timer_continue.Tick += Game_Continue_Invalidate;
    
                i++;
            }
    
            private void Game_Continue_Invalidate(object sender, EventArgs e)
            {
                for (int i = 0; i < this.i; i++)
                    panels[i].Invalidate();
            }
    
            private void Game_Continue(object sender, PaintEventArgs e)
            {
                e.Graphics.Clear(Color.White);
    
                ((Panel)sender).Width++;
                ((Panel)sender).Height++;
                e.Graphics.DrawEllipse(pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1);
            }
        }
    }

    What I need for is just a man who can make a little corrections.

    All the problem is simple!

    Should be:

    1. Draw circle.

    2. Increase circles by the timer interval 1000.

    Problem:

    1. Increasing circles faster by multiple calls of .Paint, I may be wrong.

    Please help!

    Tuesday, August 19, 2014 3:25 PM
  • Check for a double-wiring.

    In button1_Click() you have timer_game.Tick += Game_Start; In the Form1.button1, check the Events to make sure that Click is left blank.

    Also check that Form1.Paint event is left blank.

    Leave those blank in the Design because you are manually tying them in the code.


    VP

    Tuesday, August 19, 2014 7:16 PM
  • Move the size adjustment into the timer tick handler instead of the paint handler.

    Try making these changes:

    private void Game_Continue_Invalidate( object sender, EventArgs e )
    {
        for( int i = 0; i < this.i; i++ ) {
            panels[i].Width++;
            panels[i].Height++;
            panels[i].Invalidate();
        }
    }
    
    private void Game_Continue( object sender, PaintEventArgs e )
    {
        e.Graphics.Clear( Color.White );
    
        e.Graphics.DrawEllipse( pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1 );
    }
    

    Wednesday, August 20, 2014 2:09 AM
  • Also, for what it's worth, if you like retained mode drawing (as you have demonstrated by trying to animate panels), I strongly suggest you switch to using Windows Presentation Foundation (WPF) now.

    The paradigm for Graphics Rendering in WPF more closely matches your line of thinking, and rather than using a timer, you just add a handler for the global CompositionTarget.Render.  Easier, more efficient, prettier graphics results, smoother animation, GPU acceleration.  There are so many reasons to use WPF (provided you like retained mode -- which you seem to.)

    Wednesday, August 20, 2014 2:36 AM
  • Guys, I gave the code to you, there is no magic, it is a simple code and it should work, right?

    If you can, please, just fix the code, don't write a new one.

    Wyck, it didn't help.

    I used learning Winforms for 2 years, I can't just switch to.

    Wednesday, August 20, 2014 9:20 AM
  • Ok guys, you mean that you can't fix so a simple code!?)

    You mean it is absolutely impossible to write such a game in C# in such a way!?)


    • Edited by Ziya Ceferov Wednesday, August 20, 2014 10:35 AM
    Wednesday, August 20, 2014 10:35 AM
  • Ok guys, you mean that you can't fix so a simple code!?)

    You mean it is absolutely impossible to write such a game in C# in such a way!?)


    Ayayay! We are being nice trying to help. Please be kind to us.

    I have copied your code, then I ran your code, then I saw what was wrong with it, then I fixed it. Then I posted the solution..... as far as I understand it. Your circles appear faster than 1 per second. I got it to exactly 1 per second, which is 1000 milli-seconds, just as you coded it.

    But in case I didn't understand it correctly, be kind and maybe I'll try again.


    VP

    Wednesday, August 20, 2014 12:06 PM
  • I said for fun kinda joke) Sorry.

    If you wanna help, you can copy my code, fix and reply a complete working code.

    But I really started getting worried that such a little problem might be serious in C#.

    Wednesday, August 20, 2014 1:25 PM
  • I said for fun kinda joke) Sorry.

    If you wanna help, you can copy my code, fix and reply a complete working code.

    But I really started getting worried that such a little problem might be serious in C#.

    Apology accepted.

    And I did fix it. The source code as you posted is not the problem. The problem is in the design view. In the Properties section you see a list of properties. If you click on that lightning bolt, you see a list of events. Make sure your "Click" and "Paint" are left blank. That's how I resolved it.


    VP

    Wednesday, August 20, 2014 2:03 PM
  • Forms Click is empty.

    > That's how I resolved it.

    On my code?

    If you look at my code you can see that i create multiple panels after an application starts and all of them are added by Paint.

    Wednesday, August 20, 2014 2:22 PM
  • Forms Click is empty.

    > That's how I resolved it.

    On my code?

    If you look at my code you can see that i create multiple panels after an application starts and all of them are added by Paint.

    I call it ZiyaCircles just so I can work with it.

    This is Form1.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace ZiyaCircles
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private Random r1 = new Random();
            public Pen pen;
            private Panel[] panels;
            private int i = 0;
            private int length = 100;
    
            private void button1_Click(object sender, EventArgs e)
            {
                panels = new Panel[length];
                pen = new Pen(Color.Black);
                pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset;
                pen.Width = 1;
    
                timer_continue.Interval = 1000;
                timer_continue.Enabled = true;
    
                timer_game.Interval = 1000;
                timer_game.Enabled = true;
                timer_game.Tick += Game_Start;
            }
    
            private void Game_Start(object sender, EventArgs e)
            {
                int i1 = r1.Next(0, this.Width);
                int i2 = r1.Next(0, this.Height);
    
                panels[i] = new Panel();
                panels[i].Parent = this;
                panels[i].BackColor = Color.White;
                panels[i].Location = new Point(i1, i2);
                panels[i].Width = 1;
                panels[i].Height = 1;
                panels[i].Paint += Game_Continue;
    
                if (i == 0)
                    timer_continue.Tick += Game_Continue_Invalidate;
    
                i++;
            }
    
            private void Game_Continue_Invalidate(object sender, EventArgs e)
            {
                for (int i = 0; i < this.i; i++)
                    panels[i].Invalidate();
            }
    
            private void Game_Continue(object sender, PaintEventArgs e)
            {
                e.Graphics.Clear(Color.White);
    
                ((Panel)sender).Width++;
                ((Panel)sender).Height++;
                e.Graphics.DrawEllipse(pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1);
            }
    
        }
    }
    

    Here is Form1.Designer.cs:

    namespace ZiyaCircles
    {
        partial class Form1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.timer_game = new System.Windows.Forms.Timer(this.components);
                this.timer_continue = new System.Windows.Forms.Timer(this.components);
                this.button1 = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // timer_game
                // 
                this.timer_game.Interval = 1000;
                // 
                // timer_continue
                // 
                this.timer_continue.Interval = 1000;
                this.timer_continue.Tick += new System.EventHandler(this.Game_Continue_Invalidate);
                // 
                // button1
                // 
                this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                this.button1.Location = new System.Drawing.Point(537, 407);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(624, 442);
                this.Controls.Add(this.button1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private System.Windows.Forms.Timer timer_game;
            private System.Windows.Forms.Timer timer_continue;
            private System.Windows.Forms.Button button1;
        }
    }
    
    

    One thing to note, there's only 1 button, the one you clicked on in your video.


    VP

    Wednesday, August 20, 2014 3:01 PM
  • It works same as my code on my computer. How does it work on your computer?

    I hope the problem will be solved.


    Wednesday, August 20, 2014 3:12 PM
  • Guys, I gave the code to you, there is no magic, it is a simple code and it should work, right?

    If you can, please, just fix the code, don't write a new one.

    Wyck, it didn't help.

    I used learning Winforms for 2 years, I can't just switch to.

    The fix I gave you didn't help?  How so?  What are you observing now?  What happens that you don't like?  Just saying "it didn't help" tells me nothing.  What's wrong now?

    For me, this fixed the fact that the animation was "too fast".

    Wednesday, August 20, 2014 3:50 PM
  • It works same as my code on my computer. How does it work on your computer?

    I hope the problem will be solved.


    A grand circle appears and grows once per second. It is similar to your video, except only once per second. Is that right? Or do you want something else?


    VP

    Wednesday, August 20, 2014 3:50 PM
  • On my computer it appears and suddenly gets much more bigger and then starts getting bigger once per second just like what I had.

    A circle should appear at minimal size 0 and get bigger.

    I captured a video of the problem using my code and your code.

    http://youtu.be/pvzD09u31UU

    Wednesday, August 20, 2014 7:57 PM
  • On my computer it appears and suddenly gets much more bigger and then starts getting bigger once per second just like what I had.

    A circle should appear at minimal size 0 and get bigger.

    I captured a video of the problem using my code and your code.

    http://youtu.be/pvzD09u31UU

    So......

    ?


    VP

    Wednesday, August 20, 2014 9:16 PM
  • On my computer it appears and suddenly gets much more bigger and then starts getting bigger once per second just like what I had.

    A circle should appear at minimal size 0 and get bigger.

    I captured a video of the problem using my code and your code.

    http://youtu.be/pvzD09u31UU

    Did you try with my code suggestion?  It should fix what you see.

    It's a small change to your code.  I'll post my changes again just so you know which code I'm talking about.  Just replace your Game_Continue_Invalidate and Game_Continue functions with these:

    private void Game_Continue_Invalidate( object sender, EventArgs e )
    {
        for( int i = 0; i < this.i; i++ ) {
            panels[i].Width++;
            panels[i].Height++;
            panels[i].Invalidate();
        }
    }
    
    private void Game_Continue( object sender, PaintEventArgs e )
    {
        e.Graphics.Clear( Color.White );
    
        e.Graphics.DrawEllipse( pen, 0, 0, ((Panel)sender).Width - 1, ((Panel)sender).Height - 1 );
    }
     

    Again, the point here is to change where you were doing Width++ and Height++.

    You might also want it to update more frequently than once per second.  1000ms is a pretty slow interval for animation  that's only 1 fps.  You might try an interval of 50ms.  That would be 20 fps.  (1000ms / 50ms = 20fps)

    • Marked as answer by Ziya Ceferov Thursday, August 21, 2014 6:10 AM
    Thursday, August 21, 2014 1:26 AM
  • OH YEAH!!! The problem is solved, I marked the best answer. Thank you guys!

    Yes, it used to start like on your picture, but it is solved.


    Thursday, August 21, 2014 6:12 AM