我正在嘗試制作一個顯示函式圖的 Windows 表單應用程式。

我怎樣才能拉伸圖表,使其更多地向兩側延伸?
private void Graphs_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Black), 0, ClientSize.Height / 2, ClientSize.Width, ClientSize.Height / 2);
e.Graphics.DrawLine(new Pen(Color.Black), ClientSize.Width / 2, 0, ClientSize.Width / 2, ClientSize.Height);
for (double x = -100; x < 100; x = 0.1)
{
double y = x * x * -1;
//y = x * -1;
//y = Math.Sqrt(x) * -1;
//y = 1 / x;
try
{
e.Graphics.FillEllipse(new SolidBrush(Color.Red), (ClientSize.Width / 2) - 5 Convert.ToInt32(x), (ClientSize.Height / 2) - 5 Convert.ToInt32(y), 10, 10);
}
catch (Exception)
{
}
}
}
uj5u.com熱心網友回復:
為 x 和 y 添加單獨的縮放因子;目前你有 y = x2| -100<x<100,因此 y 介于 0 和 10,000 之間。
沒有 1:1 的縱橫比可以在方框中顯示該曲線,因此您可以減少顯示或以不同方式縮放軸。
我會修復視口,比如 -100<=x<=100 和 0<=y<=10000 然后從 ClientSize 和視口范圍計算 xScale 和 yScale。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/468868.html
上一篇:java:我應該在執行緒的運行方法中每秒呼叫一個方法50x,僅使用方法睡眠(此處所有其他執行緒都帶有計時器)
下一篇:.NETWinForm中的面板
