In this post, we will add the grid to the Schematic Canvas. The grid functionality is setup in MainForm.
- Add the grid gap attribute to MainForm
// The grid spacing.
public const int grid_gap = 10;
- Add the DrawBackgoundGrid() helper function to MainForm
// Draw the background grid as a Bitmap
private void DrawBackgroundGrid()
{
Bitmap bm = new Bitmap(
schematicCanvas.ClientSize.Width,
schematicCanvas.ClientSize.Height);
for (int x = 0; x < schematicCanvas.ClientSize.Width; x += grid_gap)
{
for (int y = 0; y < schematicCanvas.ClientSize.Height; y += grid_gap)
{
bm.SetPixel(x, y, Color.DarkGray);
}
}
schematicCanvas.BackgroundImage = bm;
}
- Add the Resize() event handler and call the DrawBackgroudGrid() function
No comments:
Post a Comment