The new software needs to draw a grid, and the shading like VISIO is easy to align when drawing. In WinForm, in the painting event, you can draw a line on the canvas through Graphics through computation. It will obviously be slow and there are many codes.
In WPF, it can be simpler. it is not convenient to draw a proper number of straight lines and improve performance. You can create a Group and add all the straight lines to the Group, then use RenderTransform or LayoutTransform to scale according to the scaling ratio. Another simpler method is to use ImageBrush. example:
Private DrawingBrush _ gridBrush;
Private void docCanvas_Loaded (object sender, RoutedEventArgs e)
{
If (_ gridBrush = null ){
_ GridBrush = new DrawingBrush (new GeometryDrawing (
New SolidColorBrush (Colors. White ),
New Pen (new SolidColorBrush (Colors. LightGray), 1.0 ),
New RectangleGeometry (new Rect (0, 0, 20, 20 ))));
_ GridBrush. Stretch = Stretch. None;
_ GridBrush. TileMode = TileMode. Tile;
_ GridBrush. Viewport = new Rect (0.0, 0.0, 20, 20 );
_ GridBrush. ViewportUnits = BrushMappingMode. Absolute;
DocCanvas. Background = _ gridBrush;
}
}
In fact, it is to use small rectangles to spell out the mesh of the background.
Author: nocky