我有一个坐标系(请参见下面的屏幕截图),并希望在其上放置点。但是,这些点的值大于面板的像素(例如x = 4415615.076; y = 113097.900)。我无法弄清楚如何使绘制的线条适应这些巨大的数字,以及如何将点拟合到此坐标系中。请提出任何解决方案。
private void CoordinateSystemPaint(object sender,PaintEventArgs e)
{
Graphics g = e.Graphics;
DrawAxes(g);
}
private void DrawAxes(Graphics g)
{
var m0 = Matrix3x2.CreateTranslation(coordinateSystemPanel.Width / 2,coordinateSystemPanel.Height / 2);
g.Transform = Matrix3x2ToMatrix(m0);
g.DrawLine(Pens.LightBlue,-coordinateSystemPanel.Width / 2,coordinateSystemPanel.Width / 2,0);
g.DrawLine(Pens.LightBlue,-coordinateSystemPanel.Height / 2,coordinateSystemPanel.Height / 2);
g.DrawString("X",this.Font,brushes.LightBlue,coordinateSystemPanel.Width / 2 - 20,-20);
g.DrawString("Y",5,-coordinateSystemPanel.Height / 2 + 5);
int tick = 50;
StringFormat sf = new StringFormat
{
Alignment = StringAlignment.Far
};
for (int i = -200; i <= 200; i += tick)
{
g.DrawLine(Pens.LightBlue,i,-3,3);
g.DrawLine(Pens.LightBlue,3,i);
SizeF sizeXTick = g.MeasureString(i.ToString(),this.Font);
if(i!=0)
{
g.DrawString(i.ToString(),i + sizeXTick.Width / 2,4f,sf);
g.DrawString((-i).ToString(),-3f,i - sizeXTick.Height / 2,sf);
} else
{
g.DrawString("0",new PointF(i - sizeXTick.Width / 3,4f),sf);
}
}
}
private Matrix Matrix3x2ToMatrix(Matrix3x2 m)
{
return new Matrix(m.M11,m.M12,m.M21,m.M22,m.M31,m.M32);
}