winforms - Strange rotation in C# graphics -
i using onpaint method in class class1 : panel.
protected override void onpaint(painteventargs e) { base.onpaint(e); graphics g = e.graphics; } to rotate , draw rectangle using
matrix m = new matrix(); m.rotateat(90, rotationpoint); g.transform = m; g.fillrectangle(brushes.black, rectangle) the problem is, rotation isn't working want to.
red square rotation point , it's located in middle-top of rectangle. how set x, y , rotation point rotation work properly?
after rotating @ 90 degress should this

red pixel still @ same location.
rotation point not point, want rotate. point, around which graphics rotated. if draw rectangle on top of graphics , want rotate (rectangle) - should set rotation point center of graphics , rotate image 90 degrees.
here example, want:
base.onpaint(e); var g = e.graphics; var width = g.visibleclipbounds.width; var height = g.visibleclipbounds.height; var rotationpoint = new pointf(width / 2, height / 2); ; // draw center point g.fillrectangle(brushes.red, new rectanglef(rotationpoint.x - 5, rotationpoint.y - 5, 10, 10)); using (var path = new graphicspath()) { var rectangle = new rectanglef((width - 10) / 2, 0, 10, 10); var m = new matrix(); m.rotateat(90, rotationpoint); path.addrectangle(rectangle); path.transform(m); // draw rotated point g.fillpath(brushes.black, path); }
Comments
Post a Comment