我绘图上的控制的曲线图,但0,0是在控制的顶部左手角落。有没有一种方法来翻转坐标,以便0,0是控制的左下角?
I am drawing a graph on a control, but 0,0 is at the top-left hand corner of the control. Is there a way to flip the coordinates so that 0,0 is at the lower left corner of the control?
推荐答案
如果你正在使用的WinForms,那么你可能会发现,你可以将Y轴采用的 Graphics.ScaleTransform :
If you are using WinForms, then you might find that you can flip the Y-Axis using Graphics.ScaleTransform:
private void ScaleTransformFloat(PaintEventArgs e)
{
// Begin graphics container
GraphicsContainer containerState = e.Graphics.BeginContainer();
// Flip the Y-Axis
e.Graphics.ScaleTransform(1.0F, -1.0F);
// Translate the drawing area accordingly
e.Graphics.TranslateTransform(0.0F, -(float)Height);
// Whatever you draw now (using this graphics context) will appear as
// though (0,0) were at the bottom left corner
e.Graphics.DrawRectangle(new Pen(Color.Blue, 3), 50, 0, 100, 40);
// End graphics container
e.Graphics.EndContainer(containerState);
// Other drawing actions here...
}
您只需要,如果你想使用常规的坐标系,以及做更多的图纸包含的开始/结束容器调用。是MSDN 提供的图形容器的更多信息
You only need to include the begin/end container calls if you want to do additional drawing using the regular coordinate system as well. More information on graphics containers is available on MSDN.
由于在评论中提到汤姆,这种方法需要的身高
值可用一个正确的值。如果你试试这个,看看什么正在绘制,确保值是正确的调试。
As mentioned by Tom in the comments, this approach requires the Height
value to be available with a correct value. If you try this and see nothing being drawn, ensure that value is correct in a debugger.
相关推荐
最新文章