I need to know how to make the short code snippet more efficient.
There is an inner and outer loop, and basically the code draws squares, one next to the other. Then it figures out if it should draw two more lines (in form of a cross), and if it should draw one last triangle. Most of the work is done inside the two loops though.
When the code draws a grid of 200 by 200 squares, it's good. It can even draw a grid 350 by 350 squares (122500 squares), but with a little over 1 second delay.
Anything simple I can do to improve this??? :) Thanks!
protected override void OnPaint(PaintEventArgs e)
Graphics g = e.Graphics;
int cellHeight = this.CellHeight * this.Zoom;
int cellWidth = this.CellWidth * this.Zoom;
int nbrColumns = this.Columns;
int nbrRows = this.Rows;
// Get negative x & y coordinates of scroll
scrollOffset = new Size(this.AutoScrollPosition);
// Draw cells
for (int row = 0; row < nbrRows; row++)
for (int col = 0; col < nbrColumns; col++)
Point cellLocation = new Point(col * cellWidth + scrollOffset.Width,
row * cellHeight + scrollOffset.Height);
// Define cell parameter
Rectangle cellRect = new Rectangle(cellLocation.X,
// Only draw cell if it needs to be painted
_grid.getFillColor(col, row)), cellRect);
_grid.getBorderColor(col, row), 1), cellRect);