c# - Can rectangle be split in rows and columns? -
private void panel1_paint(object sender, painteventargs e) { pen mypen = default(pen); mypen = new pen(system.drawing.color.red, 3); mypen.dashstyle = system.drawing.drawing2d.dashstyle.dash; //for dash line in rectangle pen mypen1 = default(pen); mypen1 = new pen(system.drawing.color.blue, 1); mypen1.dashstyle![enter image description here][2] = system.drawing.drawing2d.dashstyle.dash; //pen mypen2 =default(pen); //mypen2 = new pen(system.drawing.color.yellow, 3); //mypen2.dashstyle = system.drawing.drawing2d.dashstyle.dash; //pen mypen3 = default(pen); //mypen3 = new pen(system.drawing.color.violet, 1); //mypen3.dashstyle = system.drawing.drawing2d.dashstyle.dash; l1 = rect1lt.x + 5; t1 = rect1lt.y + 5; w1 = rect1rb.x - rect1lt.x; h1 = rect1rb.y - rect1lt.y; e.graphics.drawrectangle(mypen, new system.drawing.rectangle(l1, t1, w1, h1)); e.graphics.drawrectangle(mypen1, new system.drawing.rectangle(l1, t1, w1, h1)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1lt.x, rect1lt.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1rt.x, rect1rt.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1lb.x, rect1lb.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1rb.x, rect1rb.y, 10, 10)); e.graphics.fillrectangle(brushes.blue, rect1lt); e.graphics.fillrectangle(brushes.blue, rect1rt); e.graphics.fillrectangle(brushes.blue, rect1lb); e.graphics.fillrectangle(brushes.blue, rect1rb); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1t.x, rect1t.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1r.x, rect1r.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1b.x, rect1b.y, 10, 10)); e.graphics.drawrectangle(pens.blue, new system.drawing.rectangle(rect1l.x, rect1l.y, 10, 10)); e.graphics.fillrectangle(brushes.blue, rect1t); e.graphics.fillrectangle(brushes.blue, rect1r); e.graphics.fillrectangle(brushes.blue, rect1b); e.graphics.fillrectangle(brushes.blue, rect1l); datagridview dg1 = new datagridview(); //while (!exit) //{ // var time = gettime(); // update(time); // render(time); //} }
i want divide rectangle in rows , columns , size of rows , column can changeable @ runtime? , no of rows , columns can changeable? don't want split whole rectangle want divide them in rectangle.
here simplfied example:
int cols = 7; int rows = 11; private void panel1_paint(object sender, painteventargs e) { rectangle rect = // rectangle! rectangle prect = rect; // panel2.clientrectangle; float width = 1f * prect.width / cols; float height = 1f * prect.height / rows; using (pen pen = new pen(system.drawing.color.blue, 1)) { pen.dashstyle = system.drawing.drawing2d.dashstyle.dash; (int c = 0; c < cols; c++) (int r = 0; r < rows; r++) { rectanglef rect = new rectanglef(prect.x + c * width, prect.y + r * height, width, height); e.graphics.fillrectangle(brushes.coral, rect); // e.graphics.drawrectangle(pen, rect.x, rect.y, rect.width, rect.height); } (int c = 0; c < cols; c++) e.graphics.drawline(pen, prect.x + c * width, prect.y, prect.x + c * width, prect.y + prect.height); (int r = 0; r < rows; r++) e.graphics.drawline(pen, prect.x, prect.y + r * height, prect.x + prect.width, prect.y + r * height); e.graphics.drawrectangle(pens.red, prect.x, prect.y, prect.width - 1, prect.height - 1); } }
note few changes:
- the border color , fill color must not same.
- the fill must come first or overwrite border
- i work floats fill panel completely; if cols , rows don't divide panel/rectangle size evenly, recangles not have same sizes ..
at first have ignored
dashstyle
. if want havedashstyle
must change plan! reason if draw rectangles in grid you....either have them overlapping , dashes in each others way. there
dashoffset
parameter don't think can twisted make work on grid...or need draw rectangles inside grid cells twice thick , patterns still disturb each other.
instead draw few lines shown!
here example dashes:
Comments
Post a Comment