'Cant create a grid inside panel box
Solution 1:[1]
Hopefully your code looked something like:
private void Form1_Load(object sender, EventArgs e)
{
panel1.SizeChanged += Panel1_SizeChanged;
panel1.Paint += Panel1_Paint;
}
private void Panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
int cols = 7;
int rows = 6;
int width = panel1.Width / cols;
int height = panel1.Height / rows;
for(int col=1; col<cols; col++)
{
e.Graphics.DrawLine(Pens.Black, new Point(col * width, 0), new Point(col * width, panel1.Height));
}
for(int row=1; row<rows; row++)
{
e.Graphics.DrawLine(Pens.Black, new Point(0, row * height), new Point(panel1.Width, row * height));
}
}
private void Panel1_SizeChanged(object sender, EventArgs e)
{
panel1.Invalidate();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Idle_Mind |

