Масштабирование панели в зависимости от нарисованных точек
У меня есть система координат (см. Скриншот ниже) и я располагаю на неи точки с определёнными координатами. На данныи момент, масштабирование 1:1 и не все точки помещаются в панель. Как автоматически увеличивать размер панели, при таких случаях? Пробовал AutoScroll = True и саму панель хардкорно увеличивать, однако не сработало. Пожалуйста, посоветуйте какое-нибудь решение данной задачи. Разница значении точек может достигать 50000 (метров), поэтому желательно объясните принцип масштабирования в связке с размерами панели.
private void CoordinateSystemPanel_Paint(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.LightSkyBlue, -coordinateSystemPanel.Width / 2, 0, coordinateSystemPanel.Width / 2, 0);
g.DrawLine(Pens.LightSkyBlue, 0, -coordinateSystemPanel.Height / 2, 0, coordinateSystemPanel.Height / 2);
g.DrawString("X", this.Font, Brushes.LightSkyBlue, coordinateSystemPanel.Width / 2 - 20, -20);
g.DrawString("Y", this.Font, Brushes.LightSkyBlue, 5, -coordinateSystemPanel.Height / 2 + 5);
StringFormat sf = new StringFormat
{
Alignment = StringAlignment.Far
};
foreach(InitialDataEntity ide in initialDataList)
{
float x = (float)ide.DX;
float y = (float)ide.DY;
g.FillRectangle(Brushes.Red, x, -y, 4, 4);
g.DrawString((initialDataList.IndexOf(ide)+1).ToString(), this.Font, Brushes.LightSkyBlue, x, -y + 4);
}
}
private Matrix Matrix3x2ToMatrix(Matrix3x2 m)
{
return new Matrix(m.M11, m.M12, m.M21, m.M22, m.M31, m.M32);
}
