I have a drawn grid on a winforms form. When I resize the form and redraw the grid the grid lines do not exccceed the size of the original design form. I have tried both screen.GetWorkingArea(this) and this.ClientSize for the height and width. The simple maths generate the correct values. Original : numofXlines 29 numofYlines 18 end of line dims xPos 1400 yPos 850. After resize : numofXlines 51 numofYlines 27 end of line dims xPos 2500 yPos 1400.The form resizes as I drag the corner or hit 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 simply draws the line but only that part contained within the design time for shows. it develops no exceptions.