I'm trying to do something that I thought would be pretty simple: Rotate an oval around its center. So I set up a simple program to try and do that. Eventually, what I'll need to do is click on one portion of the oval, and move the mouse in a direction that will cause the oval to rotate. However, at the moment, all I want to do is right click on a form, have an oval appear with the center where the mouse click occurred, then the rotated oval draw next. And it sort of works. I say sort of because the FIRST time I click, the oval and its rotated oval, appear in exactly the correct spot, with the center of the two ovals right where my mouse pointer is. However, if I click again somewhere else on the form, the oval acts as expected (the normal and rotated oval show up, centered on each other), but the ovals are appearing in a completely random place on the form (meaning not on the e.x and e.y co-ords)
Here are the relevant parts of the code:
//this is declared at the top of the form
float theAngle = 0;
Matrix result = new Matrix();
Point center = new Point(0,0);
//this is declared in the form constructor
ovalGraphic = this.CreateGraphics();
//This is declared in the event handler for the mouseclick
if (e.Button == MouseButtons.Right)
{
ovalGraphic.DrawEllipse(pen2, e.X-50, e.Y-15, 100, 30);
xUp_lbl.Text = e.X.ToString();
yUp_lbl.Text = e.Y.ToString();
center.X = e.X;
center.Y = e.Y;
result.RotateAt(theAngle+=10, center);
ovalGraphic.Transform = result;
ovalGraphic.DrawEllipse(pen3, e.X - 50, e.Y - 15, 100, 30);
}
Can anyone see any reason why the oval is appearing in a random place after the first time I click on the form and move the mouse?