它出了什么问题?我的程序没有绘制图表。但我不明白为什么?编译器不显示错误。这是我的家庭作业。请帮帮忙。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Graphics gr = pictureBox1.CreateGraphics();
int m11, m12, m21, m22, dx, dy, ax, ay;
int xmin = -5;
int xmax = 10;
int ymin = 0;
int ymax = xmax * xmax;
ax = pictureBox1.Size.Width / (xmax - xmin);
ay = pictureBox1.Size.Height / (ymax - ymin);
m11 = ax;
m12 = 0;
m21 = 0;
m22 = ay;
dx = -xmin * ax;
dy = pictureBox1.Size.Height - ay * (-ymin);
System.Drawing.Drawing2D.Matrix M = new System.Drawing.Drawing2D.Matrix(m11, m12, m21, m22, dx, dy);
gr.Transform = M;
int x;
for (x = xmax; x < xmax; x++)
{
System.Drawing.Point p1 = new System.Drawing.Point(x, x * x);
System.Drawing.Point p2 = new System.Drawing.Point(x + 1, (x + 1) * (x + 1));
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Black, 0.2F);
gr.DrawLine(pen, p1, p2);
}
}
}
我必须在pictureBox中绘制func;
答案 0 :(得分:0)
从你在for循环中看到的,你给x赋值max,然后检查x&lt; max永远不会是真的,你甚至永远不会进入for循环的内部。
| Platform | supported sound effects formats |
|-----------------|:-----------------------------------:|
| Android Supports| .ogg , .wav format. |
| iOS | .mp3, .wav, .caf |
| Windows Desktop | .mid and .wav only |
我假设你想从0开始x计数器作为x轴上的凝视坐标。还要增加画笔的大小,因为它现在很小,所以你不会看到框中的行
for (x = xmax; x < xmax; x++)
{
System.Drawing.Point p1 = new System.Drawing.Point(x, x * x);
System.Drawing.Point p2 = new System.Drawing.Point(x + 1, (x + 1) * (x + 1));
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Black, 0.2F);
gr.DrawLine(pen, p1, p2);
}
答案 1 :(得分:0)
你的变量x永远不会低于最大值,所以你需要以最小值开始它或者你的For循环不起作用,就像Proxy在他的回答中说的那样你可以增加笔的大小如果你想要它更容易看到
int x;
for (x = xmin; x < xmax; x++) // set it to the min value at first
{
System.Drawing.Point p1 = new System.Drawing.Point(x, x * x);
System.Drawing.Point p2 = new System.Drawing.Point(x + 1, (x + 1) * (x + 1));
System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Black, 2F); // changed the value here
gr.DrawLine(pen, p1, p2);
}