6

原点をウィンドウの中央にしたい。

______________
| | ^ |
| | | | | |
| | o----->|
| | | |
|____________|

.NET は、それを左上隅に配置したいと考えています。

______________>
| | | |
| | | |
| | | |
| | | |
V____________|

ドットネットと仲良くしようとしてる..

Graphics オブジェクトを使用して C# でこれを行う方法を知っている人はいますか?

Graphics.TranslateTransform は、座標が上下逆になったままになるため、それを行いません。この Graphics.ScaleTransform(1,-1) を組み合わせても、テキストが上下逆に表示されるため、満足のいくものではありません。

4

3 に答える 3

1

テキストの描画中に、現在の変換を引き続き使用してScaleTransform(1, -1)一時的にリセットできます。

// Convert the text alignment point (x, y) to pixel coordinates
PointF[] pt = new PointF[] { new PointF(x, y) };
graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);

// Revert transformation to identity while drawing text
Matrix oldMatrix = graphics.Transform;
graphics.ResetTransform();

// Draw in pixel coordinates
graphics.DrawString(text, font, brush, pt[0]);

// Restore old transformation
graphics.Transform = oldMatrix;
于 2012-01-31T14:59:40.853 に答える
0

負の高さでグラフィックス オブジェクトを作成してみてください。特に C# ライブラリについてはわかりませんが、このトリックは最近のバージョンの GDI で機能します。

于 2009-06-23T02:02:47.957 に答える