void CDTranV::OnPaint()
时间: 2024-06-04 08:12:33 浏览: 77
MFC.zip_onpaint
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DrawGrid(dc); // Call the function to draw the grid
}
void CDTranV::DrawGrid(CDC& dc)
{
// Get the client rectangle
CRect rect;
GetClientRect(&rect);
// Calculate the size of each cell
int cellWidth = rect.Width() / m_numCols;
int cellHeight = rect.Height() / m_numRows;
// Draw the grid lines
for (int i = 0; i <= m_numCols; i++)
{
int x = i * cellWidth;
dc.MoveTo(x, 0);
dc.LineTo(x, rect.Height());
}
for (int i = 0; i <= m_numRows; i++)
{
int y = i * cellHeight;
dc.MoveTo(0, y);
dc.LineTo(rect.Width(), y);
}
// Draw the symbols
for (int i = 0; i < m_numRows; i++)
{
for (int j = 0; j < m_numCols; j++)
{
int symbol = m_symbols[i][j];
if (symbol != 0)
{
// Calculate the position of the symbol
int x = j * cellWidth + cellWidth / 2;
int y = i * cellHeight + cellHeight / 2;
// Draw the symbol
dc.TextOut(x, y, CString(symbol));
}
}
}
}
阅读全文