I create a control set of rectangles in code and fill a window to resemble a grid. The code executes very slow.
It takes about 10 seconds before it even starts to draw. The actual drawing is about 2 secs. Intel Core i5 8Gb.
[code] 'Draw boxes in a double loop
'with step 9 (width 8 + 1)
For j as Integer = 1 to (MainWindow.Height- Rectangle1.Height) step 9
For i As Integer = 1 To MainWindow.Width step 9
Dim b As New Box
b.Visible = True
b.Left =i
b.top = j
BoxCounter = BoxCounter + 1
Next
next
'adjust window width to fit the edges
MainWindow.Width = MainWindow.Width + (MainWindow.Width mod 9) -1
MainWindow.Height = MainWindow.Height + ((MainWindow.Height - Rectangle1.Height) mod 9) +1
[/code]
Is there a way to speed things up? Current example draws 3015 boxes.
create 4 global constants (rWidth, rHeight, rXspace, rYSpace)
In the PAINTEVENT of the canvas
dim x as integer
dim y as integer
//
for x=1 to g.width-rWidth step rWidth+rXSpace
for y=1 to g.height-rHeight step rHeight+rYSpace
g.drawrect x,y,rWidth,rHeight
next y
next x
in the MouseDown Event
x=(x/(rWidth+rXspace))
y=(y/(rHeight+rYSpace))
msgbox "You clicked "+str(x)+","+str(y)
// You may need to adjust these calculations based on your need, FOR ILLUSTRATION PURPOSES ONLY
rHeight is how TALL the rectangle should be
rWidth is the Width (incase you want NON-SQUARES)
rXspace is how much space between them horizontally
rYSpace is space vertically
This draws 11,000 rectanges is 0.07 seconds or 536 times faster than you example
[ANY CODE SAMPLES PROVIDED ARE FOR ILLUSTATION PURPOSES ONLY, AND IT IS UP TO THE USER TO DETERMINE ANY/ALL MODIFICATION REQUIRED TO MAKE IT FIT THEIR PURPOSE OR DESIGN,]
create 4 global constants (rWidth, rHeight, rXspace, rYSpace)
In the PAINTEVENT of the canvas
dim x as integer
dim y as integer
//
for x=1 to g.width-rWidth step rWidth+rXSpace
for y=1 to g.height-rHeight step rHeight+rYSpace
g.drawrect x,y,rWidth,rHeight
next y
next xg
in the MouseDown Event
x=(x/(rWidth+rXspace))
y=(y/(rHeight+rYSpace))
msgbox "You clicked "+str(x)+","+str(y)
// You may need to adjust these calculations based on your need, FOR ILLUSTRATION PURPOSES ONLY
rHeight is how TALL the rectangle should be
rWidth is the Width (incase you want NON-SQUARES)
rXspace is how much space between them horizontally
rYSpace is space vertically
This draws 11,000 rectanges is 0.07 seconds or 536 times faster than you example
[ANY CODE SAMPLES PROVIDED ARE FOR ILLUSTATION PURPOSES ONLY, AND IT IS UP TO THE USER TO DETERMINE ANY/ALL MODIFICATION REQUIRED TO MAKE IT FIT THEIR PURPOSE OR DESIGN,][/quote]
Thanks Dave,
I knew bout the canvas ofcourse.
Thx.
Ps Your disclaimer? Should I worry? Do I have to sign anything?
seems people have been doing direct copy/paste and wondering why in some situations it didn’t solve their problem. Without taking the due dilegnce to figure out what was being told to them, and the context in which it was offered.