#1. Write code
#2. Debug
#3. Make twice as fast
#4. Make even faster...
Anyway that's the way it usally is for me when i'm drawing stuff on a form. Now i've come to quite a different problem - that of drawing a rectangle at a reasonable speed, this time i have no idea how to make it faster. For my speed experimenting i'm covering a form with recangles but it's REALLY SLOW. I'm hoping that i'm missing a major concept in graphics drawing in vb2010 so here's my code so that you can tell me what's wrong:
Guess what? That takes about .15 seconds to draw each time!Code:Public Class Form1 Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim s = Microsoft.VisualBasic.Timer Dim x As Integer, y As Integer, r As Rectangle, g As Graphics = Me.CreateGraphics g.Clear(Me.BackColor) For x = 0 To Me.Width Step 30 For y = 0 To Me.Height Step 15 r = New Rectangle(x, y, 30, 15) g.DrawRectangle(Pens.Black, r) Next Next Debug.Print(Microsoft.VisualBasic.Timer - s) End Sub End Class
I did a direct comparison to vb6 using this code:
Guess what? That takes about .015625 seconds to draw each time!Code:Private Sub Form_Paint() Dim start start = Timer Cls For X = 0 To Me.ScaleWidth Step 30 For Y = 0 To Me.ScaleHeight Step 15 Me.Line (X, Y)-(X + 30, Y + 30), vbBlack, B Next Next Debug.Print Timer - start End Sub
Something has got to be really wrong with my method in .net. I'm just waiting to kick myself![]()






Reply With Quote