制作+ Y UP,移动产地C#System.Drawing.Graphics [英] Make +y UP, Move Origin C# System.Drawing.Graphics
问题描述
我要的起源是在我的窗口中心
I want the origin to be at the center of my window.
______________
| ^ |
| | |
| o----->|
| |
|____________|
.NET希望它是在左上角。
.NET wants it to be in the top left hand corner.
_____________>
| |
| |
| |
| |
V____________|
点网,我试图相处..
Dot net and I are trying to get along..
有谁知道如何只使用Graphics对象做这在C#?
Does anyone know how to do this in C# just using the Graphics object?
Graphics.TranslateTransform,因为它留下的坐标翻转倒扣不这样做。结合这Graphics.ScaleTransform(1,-1)是不能令人满意的,因为任何使文本出现倒挂。
Graphics.TranslateTransform doesn't do it since it leaves the coordinates flipped upside down. Combining this Graphics.ScaleTransform(1,-1) isn't satisfactory either since that makes text appear upside down.
推荐答案
一的解决办法是使用TranslateTransform属性。然后,而不是使用点/的PointF结构,你可以创建自己的FlippedPoint / FlippedPointF结构有隐式转换为点/的PointF(但铸造他们COORDS得到翻转):
One solution would be to use the TranslateTransform property. Then, instead of using the Point/PointF structs you could create a FlippedPoint/FlippedPointF structs of your own that have implicit casts to Point/PointF (but by casting them the coords get flipped):
public struct FlippedPoint
{
public int X { get; set; }
public int Y { get; set; }
public FlippedPoint(int x, int y) : this()
{ X = x; Y = y; }
public static implicit operator Point(FlippedPoint point)
{ return new Point(-point.X, -point.Y); }
public static implicit operator FlippedPoint(Point point)
{ return new FlippedPoint(-point.X, -point.Y); }
}
这篇关于制作+ Y UP,移动产地C#System.Drawing.Graphics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!