c# - Rotate the ellipse with specified angle on paint event -
i trying draw ellipse according mouse points(starting , ending point) using next code...
private void picturebox1_mousedown(object sender, mouseeventargs e) { start = new point(e.x, e.y); // point mousedownlocation = picturebox1.pointtoclient(new point(e.x, e.y)) mrect = new rectangle(e.x, e.y, 0, 0); }
and
private void picturebox1_mouseup(object sender, mouseeventargs e) { end = new point(e.x, e.y); picturebox1.invalidate(); if (listrect.count <= 4) { listrect.add(mrect); this.getobjectpopup(e); } else { messagebox.show("maximum 5 selection per image", "alert", messageboxbuttons.ok); } }
and on paint event wrote next code
private void picturebox1_paint(object sender, painteventargs e) { color c1 = color.fromargb(50, color.green); foreach (rectangle rect in listrect) { using (pen pen = new pen(color.red, 2)) { float angle = (float)angle(start, end); matrix transformmatrix = new matrix(); transformmatrix.translate(200.0f, 0.0f); e.graphics.rotatetransform(angle); // e.graphics.multiplytransform(transformmatrix, matrixorder.append); e.graphics.drawellipse(pen, rect.x, rect.y, rect.width, rect.height); e.graphics.fillellipse(new solidbrush(c1), rect.x, rect.y, rect.width, rect.height); this.writetext(e,rect); } } }
ellipse has been drawn not along mouse starting , ending points
have tried set horizontal , vertical alignment?
rect.horizontalalignment = horizontalalignment.left; rect.verticalalignment = verticalalignment.top;
edit: respectively setting properties on ellipse
c#
No comments:
Post a Comment