I don't quite follow your code exactly. Why create a graphics object on the main form only to use it in the Paint event, in which a graphics object is already passed as a parameter. Also I think you're making this a tad more complicated than it is. Code below to hopefully give you what you need (or at least illustrate the principle):
csharp Code:
RectangleF myrect = new RectangleF(300.0f, 150.0f, 30.0f, 30.0f); RectangleF myorbit = new RectangleF(200.0f, 100.0f, 115.0f, 65.0f); float ellipse_angle = 0.0f; float rotation_angle = 0.0f; private void Main_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawEllipse(Pens.Red, myorbit.X, myorbit.Y, myorbit.Width, myorbit.Height); using (System.Drawing.Drawing2D.Matrix transformation = new System.Drawing.Drawing2D.Matrix() { }) { transformation.Translate(myrect.X, myrect.Y); transformation.Rotate(rotation_angle); transformation.Translate(-myrect.X, -myrect.Y); e.Graphics.Transform = transformation; } e.Graphics.DrawRectangle(Pens.AntiqueWhite, myrect.X, myrect.Y, myrect.Width, myrect.Height); } private void timerxoay_Tick(object sender, EventArgs e) { ellipse_angle += (float)(Math.PI / 40.0); rotation_angle += (float)(Math.PI / 10.0); myrect.Location = new PointF(myorbit.X + (float)((Math.Cos(ellipse_angle) + 1.0) * myorbit.Width / 2.0), myorbit.Y + (float)((Math.Sin(ellipse_angle) + 1.0) * myorbit.Height / 2.0)); this.Invalidate(); } private void cmdrotate_Click(object sender, EventArgs e) { timerxoay.Enabled = !timerxoay.Enabled; }
Regards Tom




Reply With Quote