The schematicCanvas (pictureBox) supports drawing graphics such as lines, rectangles, ellipses, curves, and paths (see Microsoft Documentation). It will draw any graphics listed in the "paint" event handler.
In the Test Diagram designer window, display the events and double click on the blank area next to the Paint event. Add the following code to the event handler to draw a simple rectangle.
private void schematicCanvas_Paint(object sender, PaintEventArgs e)
{
// Draw a simple rectangle with black border and no fill color
Pen pen = new Pen(Color.Black);
e.Graphics.DrawRectangle(pen, 100, 100, 100, 100);
}
// Draw a simple rectangle with black border and no fill color
Pen pen = new Pen(Color.Black);
}
We have succeeded in drawing on the schematicCanvas, however, there are two problems with this approach.
- The pen is created everytime the Paint event occurs which can be many times per second.
- We can only draw a rectangle at a fixed location.
We need a way to draw a shape (component) selected by the user from a menu button.
No comments:
Post a Comment