[英]C# - calling the paint event handler
I want to call my paint event when i click a button. 我想在单击按钮时调用绘画事件。 I have this:
我有这个:
private void btnDrawMap_Click(object sender, EventArgs e)
{
rows = Convert.ToInt32(this.numRows);
cols = Convert.ToInt32(this.numCols);
defineCellWallsList();
defineCellPositionsList();
pictureBox1_Paint_1;
}
I don't think you can call it in this way. 我认为您不能这样称呼。 All
pictureBox1_Paint_1
does is: pictureBox1_Paint_1
所做的全部是:
private void pictureBox1_Paint_1(object sender, PaintEventArgs e)
{
myGameForm.drawMap(e, mapCellWallList, mapCellPositionList);
}
So if i can call myGameForm.drawMap
instead, that would be fine. 因此,如果我可以改为调用
myGameForm.drawMap
,那就很好。 Which is: 这是:
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);
}
It requires a paintEventArg
and the btnDrawMap_Click
requires an eventArg, so i changed the btnDrawMap_Click
eventArg parameter to paintEventArg, however it has an error stating that btnDrawMap_Click
has not overloaded method that takes an eventHandler. 它需要
paintEventArg
,而btnDrawMap_Click
需要eventArg,所以我将btnDrawMap_Click
eventArg参数更改为paintEventArg,但是它有一个错误,指出btnDrawMap_Click
尚未重载采用eventHandler的方法。
Any help appreciated, thanks. 任何帮助表示赞赏,谢谢。
只需调用Invalidate()
,它会强制PictureBox
重绘自身,从而调用您的Paint
事件:
pictureBox1.Invalidate();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.