我在程序的from1_Paint事件中编写了以下代码:
其中graphics_array是一个已赋值的二维结构体数组, width也已赋值 但运行后没有任何反应这是怎么回事???
Graphics mygraphics =this.CreateGraphics();
Pen mypen = new Pen(Color.Black);
for (i = 0; i < len; i++)
{
for (j = 0; j < len; j++)
{
mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width);
}
}
其中graphics_array是一个已赋值的二维结构体数组, width也已赋值 但运行后没有任何反应这是怎么回事???
Graphics mygraphics =this.CreateGraphics();
Pen mypen = new Pen(Color.Black);
for (i = 0; i < len; i++)
{
for (j = 0; j < len; j++)
{
mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
,直接写LOAD事件里面不会显示的
}
有没有执行,或画到了该form的外面.
另:
Graphics mygraphics =this.CreateGraphics();
可用
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics mygraphics = e.Graphics;
............
}
pictureBox1.Image = imgPic;
Graphics grp = Graphics.FromImage(imgPic);
grp.SmoothingMode = SmoothingMode.AntiAlias;
pictureBox1.Refresh();
Pen mypen = new Pen(Color.Black);
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
grp.DrawRectangle(mypen, i, j, i+i,j*j);
}
}
放个 pictureBox1试一试
记得给分哦
Pen mypen = new Pen(Color.Black);
for (i = 0; i < len; i++)
{
for (j = 0; j < len; j++)
{
mygraphics.DrawRectangle(mypen, graphics_array[i, j].x, graphics_array[i, j].y, width, width);
}
}