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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Want code fragment to move line around on Form

Want code fragment to move line around on Form

Scheduled Pinned Locked Moved C#
graphics
4 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.
  • . Offline
    . Offline
    ...---...
    wrote on last edited by
    #1

    Hi, Please see the following code below: ////////////////////////////////////////////// ..... private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { xOrigin = Form1.ActiveForm.ClientRectangle.Width/2; yOrigin = Form1.ActiveForm.ClientRectangle.Height/2; DrawThisLine(e.Graphics); } public void DrawThisLine(Graphics g) { Pen pen = new Pen(Color.Black, 3); g.DrawLine(pen, xOrigin, yOrigin, xOrigin + 75, yOrigin + 75); } private void timer1_Tick(object sender, System.EventArgs e) { } .... /////////////////////////////////////////// I have tried to use the timer1 object and the timer1 event but can't seem to get the line to move around on the Form1. Ultimately I'd like it to rotate around like a clock hand but at this point I'll take any code fragment just to get it in some sort of animated motion. Thanks a lot in advance....

    G 1 Reply Last reply
    0
    • . ...---...

      Hi, Please see the following code below: ////////////////////////////////////////////// ..... private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { xOrigin = Form1.ActiveForm.ClientRectangle.Width/2; yOrigin = Form1.ActiveForm.ClientRectangle.Height/2; DrawThisLine(e.Graphics); } public void DrawThisLine(Graphics g) { Pen pen = new Pen(Color.Black, 3); g.DrawLine(pen, xOrigin, yOrigin, xOrigin + 75, yOrigin + 75); } private void timer1_Tick(object sender, System.EventArgs e) { } .... /////////////////////////////////////////// I have tried to use the timer1 object and the timer1 event but can't seem to get the line to move around on the Form1. Ultimately I'd like it to rotate around like a clock hand but at this point I'll take any code fragment just to get it in some sort of animated motion. Thanks a lot in advance....

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Well, as you are not doing anything in the timer event, you can't expect much to happen. Do some changes to what you are drawing, and cause a redraw: something += whatever; this.Invalidate(); You might want to do the drawing on something like a panel, though, so you don't have to redraw the entire window for every update. --- b { font-weight: normal; }

      . 1 Reply Last reply
      0
      • G Guffa

        Well, as you are not doing anything in the timer event, you can't expect much to happen. Do some changes to what you are drawing, and cause a redraw: something += whatever; this.Invalidate(); You might want to do the drawing on something like a panel, though, so you don't have to redraw the entire window for every update. --- b { font-weight: normal; }

        . Offline
        . Offline
        ...---...
        wrote on last edited by
        #3

        THanks, I intentionally left them blank. I think my main confusion is the fact that I have to do all the drawing in the paint handler. Once i added the timer event I can't figure out how to tie the the paint event to the timer and the function that draws the line in the paint event. :confused:

        G 1 Reply Last reply
        0
        • . ...---...

          THanks, I intentionally left them blank. I think my main confusion is the fact that I have to do all the drawing in the paint handler. Once i added the timer event I can't figure out how to tie the the paint event to the timer and the function that draws the line in the paint event. :confused:

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          That's what the Invalidate call is for. It causes a repaint. --- b { font-weight: normal; }

          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