当我点击一个按钮时,我想调用我的绘画事件。我有这个:
private void btnDrawMap_Click(object sender, EventArgs e)
{
rows = Convert.ToInt32(this.numRows);
cols = Convert.ToInt32(this.numCols);
defineCellWallsList();
defineCellPositionsList();
pictureBox1_Paint_1;
}
我不认为你可以这样称呼它。所做pictureBox1_Paint_1
的就是:
private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
{
myGameForm.drawMap(e, mapCellWallList, mapCellPositionList);
}
所以如果我可以打电话myGameForm.drawMap
,那很好。这是:
public void drawMap(PaintEventArgs e, List<List<int>> walls, List<List<int>> positions)
{
// Create a local version of the graphics object for the PictureBox.
Graphics g = e.Graphics;
// Loop through mapCellArray.
for (int i = 0; i < walls.Count; i++)
{
int[] mapData = getMapData(i, walls, positions);
int column = mapData[0];
int row = mapData[1];
int right = mapData[2];
int bottom = mapData[3];
g.DrawLine(setPen(right), column + squareSize, row, column + squareSize, row + squareSize);
g.DrawLine(setPen(bottom), column + squareSize, row + squareSize, column, row + squareSize);
}
drawMapEdges(e, walls, positions);
}
它需要一个paintEventArg
并且btnDrawMap_Click
需要一个eventArg,所以我将btnDrawMap_Click
eventArg参数更改为paintEventArg,但是它有一个错误说明btnDrawMap_Click
没有重载采用eventHandler的方法。
任何帮助表示赞赏,谢谢。