I have a drawn grid on a WinForms form. When I resize the form and redraw the grid, the grid lines do not exceed the size of the original design form. I have tried both screens. GetWorkingArea(this) and this.ClientSize for the height and width. The simple maths generates the correct values. Original: numofXlines 29 numofYlines 18 end of line dims xPos 1400 yPos 850. After resizing: numofXlines 51 numofYlines 27 ends of line dims xPos 2500 yPos 1400. The form resizes as I drag the corner or the t max button, but the redraw of the grid stops both horizontally and vertically at the boundaries of the design time form. I appreciate that is a nonproblem problem, the world works fine until I interfere, but this has me somewhat stumped.
c# .net8/9 vs2025 windows 11 Project is WinForms only
private void DrawGrid(Boolean Resize)
{
int NumOfYLines;
int NumOfXLines;
int GridHeight;
int GridWidth;
Pen ThisPen = new Pen(Color.LightSlateGray, 1);
if (!Resize)
{
GridHeight = this.Height;
GridWidth = this.Width;
}
else
{
GridHeight = this.ClientSize.Height;
GridWidth = this.ClientSize.Width;
// ThisPen = new Pen(Color.DarkRed, 1);
}
NumOfYLines = GridHeight / GridSize;
NumOfXLines = GridWidth / GridSize;
// Generate coordinates in loops
Array[,] GridCoordinates = new Array[NumOfXLines, NumOfYLines];
for (int x = 0; x < NumOfXLines; ++x)
{
int xPos = x * GridSize;
for (int y = 0; y < NumOfYLines; ++y)
{
int yPos = y * GridSize;
TheseGraphics.DrawLine(ThisPen, 0, yPos, GridWidth, yPos);
TheseGraphics.DrawLine(ThisPen, xPos, 0, xPos, NumOfXLines * GridSize);
GridCoordinates[x, y] = new int[xPos, yPos];
Misc.writeLog(
"xPos ::" + xPos.ToString() + " :: " +
"numofXlines :: " + NumOfXLines.ToString() + " :: " +
"yPos ::" + yPos.ToString() + " :: " +
"numofYlines :: " + NumOfYLines.ToString(), true
);
}
}
}
I have stepped through and can find no problem. The pen draws the line, but only that part is contained within the design time for shows. It develops no exceptions.