Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. moving ellipse

moving ellipse

Scheduled Pinned Locked Moved C#
csharpquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    t_nedelchev
    wrote on last edited by
    #1

    Hello everybody. I am working with MVS2005.My project is C# project How can I make e table with 10 raws and 10 columns and draw a moving ellipse over table. Thanks for all.

    L 1 Reply Last reply
    0
    • T t_nedelchev

      Hello everybody. I am working with MVS2005.My project is C# project How can I make e table with 10 raws and 10 columns and draw a moving ellipse over table. Thanks for all.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I am not sure what you mean by table. If its just a visual thing, you might consider using a Panel, and drawing in it: - 9 or 11 horizontal lines - 9 or 11 vertical lines - your ellipse (redrawn based on a Forms.Timer for animation) :)

      Luc Pattyn [My Articles]

      T 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, I am not sure what you mean by table. If its just a visual thing, you might consider using a Panel, and drawing in it: - 9 or 11 horizontal lines - 9 or 11 vertical lines - your ellipse (redrawn based on a Forms.Timer for animation) :)

        Luc Pattyn [My Articles]

        T Offline
        T Offline
        t_nedelchev
        wrote on last edited by
        #3

        Now I do this. private void timer1_Tick(object sender, EventArgs e) { X1 += 5; Y1 += 5; Invalidate(); SolidBrush myBrush = new SolidBrush(Color.Green); dataGridView1.Refresh(); Graphics grfx = dataGridView1.CreateGraphics(); grfx.FillEllipse(myBrush, X1, Y1, 15, 15); } But I ask is there any other way to do this

        L 1 Reply Last reply
        0
        • T t_nedelchev

          Now I do this. private void timer1_Tick(object sender, EventArgs e) { X1 += 5; Y1 += 5; Invalidate(); SolidBrush myBrush = new SolidBrush(Color.Green); dataGridView1.Refresh(); Graphics grfx = dataGridView1.CreateGraphics(); grfx.FillEllipse(myBrush, X1, Y1, 15, 15); } But I ask is there any other way to do this

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, some remarks: 1. you should call Dispose() on all objects you create from classes that offer a public Dispose() method as soon as you dont need the objects any more. It applies to both myBrush and grfx. 2. you could keep myBrush alive and reuse it over and over. you should not do that with grfx 3. I would do the painting in a paint handler, not the timer tick (but of course the x1/y1 update and the Invalidate() belong inside the tick handler). AS a result the ellipse gets redrawn also every time it got damaged (e.g. when moving another window over it without having to wait for the next timer tick (dont know what its period is). BTW The PaintEventArgs offer you a free graphics, so you then dont need CreateGraphics anymore, and dont have to Dispose() it. :)

          Luc Pattyn [My Articles]

          T 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, some remarks: 1. you should call Dispose() on all objects you create from classes that offer a public Dispose() method as soon as you dont need the objects any more. It applies to both myBrush and grfx. 2. you could keep myBrush alive and reuse it over and over. you should not do that with grfx 3. I would do the painting in a paint handler, not the timer tick (but of course the x1/y1 update and the Invalidate() belong inside the tick handler). AS a result the ellipse gets redrawn also every time it got damaged (e.g. when moving another window over it without having to wait for the next timer tick (dont know what its period is). BTW The PaintEventArgs offer you a free graphics, so you then dont need CreateGraphics anymore, and dont have to Dispose() it. :)

            Luc Pattyn [My Articles]

            T Offline
            T Offline
            t_nedelchev
            wrote on last edited by
            #5

            Hi Can you send me a sample code how can I do this in paint handler X and Y is updated in timer tick at 100ms.

            L 1 Reply Last reply
            0
            • T t_nedelchev

              Hi Can you send me a sample code how can I do this in paint handler X and Y is updated in timer tick at 100ms.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, create and wire a paint handler for your dataGridView1 or add the relevant lines to an existing one:

              private SolidBrush myBrush = new SolidBrush(Color.Green);

              private void dataGridView1_Paint(object sender, PaintEventArgs e) {
              Graphics g=e.Graphics;
              g.FillEllipse(myBrush, X1, Y1, 15, 15);
              }

              That should do it. :)

              Luc Pattyn [My Articles]

              T 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, create and wire a paint handler for your dataGridView1 or add the relevant lines to an existing one:

                private SolidBrush myBrush = new SolidBrush(Color.Green);

                private void dataGridView1_Paint(object sender, PaintEventArgs e) {
                Graphics g=e.Graphics;
                g.FillEllipse(myBrush, X1, Y1, 15, 15);
                }

                That should do it. :)

                Luc Pattyn [My Articles]

                T Offline
                T Offline
                t_nedelchev
                wrote on last edited by
                #7

                I'm so sorry but something wrong. I try this any times today. Is there something else in timer tick except to update X and Y value and to Invalidate().Because my dataGridView is repainted only when over it move another window. Sorry but I'm beginer.

                L 1 Reply Last reply
                0
                • T t_nedelchev

                  I'm so sorry but something wrong. I try this any times today. Is there something else in timer tick except to update X and Y value and to Invalidate().Because my dataGridView is repainted only when over it move another window. Sorry but I'm beginer.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Hi, if dataGridView1 is the only thing changed by your timer, then it also is the only thing that needs to be invalidated, so try dataGridView1.Invalidate() there. Dont be afraid to try a couple of things, you learn more by having a good balance between doing some experiments and asking some questions... :)

                  Luc Pattyn [My Articles]

                  T 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, if dataGridView1 is the only thing changed by your timer, then it also is the only thing that needs to be invalidated, so try dataGridView1.Invalidate() there. Dont be afraid to try a couple of things, you learn more by having a good balance between doing some experiments and asking some questions... :)

                    Luc Pattyn [My Articles]

                    T Offline
                    T Offline
                    t_nedelchev
                    wrote on last edited by
                    #9

                    It's my last question. :) The effect is the same when in timer tick I make dataGridView1.Refresh(); Byt my dataGridView1 blink every timer tick

                    L 1 Reply Last reply
                    0
                    • T t_nedelchev

                      It's my last question. :) The effect is the same when in timer tick I make dataGridView1.Refresh(); Byt my dataGridView1 blink every timer tick

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      Hi, that is no surprise, each control that gets redrawn by default starts of with clearing the background, then painting the foreground. There is an easy way to make this invisible, it is known as "double buffering" (which means the drawing is made first in an off-screen buffer, then that one is copied over the relevant part of the screen). There is Control.DoubleBuffered starting .NET 2.0; for .NET 1.x you can achieve the same effect using SetStyles on an inherited Control. Lots of articles on CP use these techniques. :)

                      Luc Pattyn [My Articles]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups