my Suggestion is to create a customized PictureBox with the Behaviour you want to have :
using System;
using System.Windows.Forms;
using System.Drawing;
public class GridPictureBox : PictureBox
{
public Size GridSize
{
get { return my_GridSize; }
set
{
my_GridSize = value;
this.Invalidate();
}
}
private Size my_GridSize = new Size(8, 8);
public Color GridColor
{
get { return my_GridColor; }
set
{
my_GridColor = value;
this.Invalidate();
}
}
private Color my_GridColor = Color.Black;
protected override void OnSizeModeChanged(EventArgs e)
{
this.Invalidate();
base.OnSizeModeChanged(e);
}
protected override void OnSizeChanged(EventArgs e)
{
this.Invalidate();
base.OnSizeChanged(e);
}
protected override void OnPaint(PaintEventArgs pe)
{
Graphics gr = pe.Graphics;
base.OnPaint(pe);
if (Image != null)
{
Point p = default(Point);
Size s = default(Size);
switch (SizeMode)
{
case PictureBoxSizeMode.Normal:
case PictureBoxSizeMode.StretchImage:
case PictureBoxSizeMode.CenterImage:
s = this.Size;
p = new Point(0, 0);
break;
case PictureBoxSizeMode.AutoSize:
s = Image.Size;
p = new Point(0, 0);
break;
case PictureBoxSizeMode.Zoom:
float factor = Math.Max(Convert.ToSingle(Image.Height) / Convert.ToSingle(this.Height), Convert.ToSingle(Image.Width) / Convert.ToSingle(this.Width));
s = new Size(Convert.ToInt32(Convert.ToSingle(Image.Width) / factor), Convert.ToInt32(Convert.ToSingle(Image.Height) / factor));
p = new Point((this.Width - s.Width) / 2, (this.Height - s.Height) / 2);
break;
}
for (int x = 0; x <= s.Width; x += my_GridSize.Width)
{
gr.DrawLine(new Pen(my_GridColor, 1), x + p.X, p.Y, x + p.X, p.Y + s.Height);
}
for (int y = 0; y <= s.Height; y += my_GridSize.Height)
{
gr.DrawLine(new Pen(my_GridColor, 1), p.X, y + p.Y, p.X + s.Width, y + p.Y);
}
}
}
}