简体   繁体   中英

how do I create a rectangle that shows height?

I am trying to make a form that creates a rectangle using a bunch of cubes using graphics but it only displays the width.

It should be as simple as:

for (var x = 0; x < width; x++)
for (var y = 0; y < height; y++)
   g.DrawRectangle(linepen, new Rectangle(x * size, y * size, Size, Size));

Also as @Jimi this should be done in the paint event, which provides you a Graphics object. This will allow it to survive form repaints, refreshes, resizes, etc.

A more efficient approach for this particular problem would be to use one rectangle for the first row, the second row, etc... then one rectangle for the first column, the second column, etc..

var rowSize = width * size;
var columnSize = height * size;
for(var x = 0; x < width; x++)
    g.DrawRectangle(linepen, new Rectangle(x*size, Y, size, columnSize)
for(var y = 0; y < height; y++)
    g.DrawRectangle(linepen, new Rectangle(X, y *size, rowSize, size)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM