Want code fragment to move line around on Form
-
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....
-
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....
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; } -
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; }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:
-
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: