shizon Posted November 15, 2004 Posted November 15, 2004 We were trying to create and destroy buttons in the usual way of a "control array" but it is too slow if trying to do about 100 buttons. Is there a better performing method than the standard way of doing it in vb.net? I thought I remember something about bit something that might work. I forget what it's called. Thanks for the help. Quote
shizon Posted November 15, 2004 Author Posted November 15, 2004 I guess I should clarify, we only create the buttons once, then it's a show/hide ordeal. Quote
Administrators PlausiblyDamp Posted November 15, 2004 Administrators Posted November 15, 2004 Could you post the relevant code? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
shizon Posted November 15, 2004 Author Posted November 15, 2004 Public Sub DoButtons(ByVal uplimit As Integer) Dim x As Integer Dim xx As Integer Dim y As Integer Dim mybutt As Button y = 5 xx = 1 For x = 1 To uplimit TheButs(x) = New System.Windows.Forms.Button TheButs(x).Size = New System.Drawing.Size(36, 36) TheButs(x).Font = New System.Drawing.Font("Microsoft Sans Serif", 6.75!, System.Drawing.FontStyle.Regular) xx += 1 If xx > 10 Then xx -= 10 Select Case x Case 11 y = 44 Case 21 y = 83 '44 + 39 Case 31 y = 122 '44 + 39 * 2 Case 41 y = 161 '44 + 39 * 3 Case 51 y = 200 '44 + 39 * 4 Case 61 y = 239 '44 + 39 * 5 Case 71 y = 278 '44 + 39 * 6 Case 81 y = 317 '44 + 39 * 7 Case 91 y = 356 '44 + 39 * 8 Case 101 y = 356 '44 + 39 * 8 End Select TheButs(x).Location = New System.Drawing.Point(y, 26 + ((xx - 1) * 38)) TheButs(x).Text = x Me.Controls.Add(TheButs(x)) AddHandler TheButs(x).Click, AddressOf ButtonsAll_Click Next x End Sub That's the sub that creates the buttons. For x = 1 To NumberofButtons TheButs(x).Visible = True Next x Sub that shows. Sub that hides is just that only with false obviously. I've tried show() and hide() Quote
Administrators PlausiblyDamp Posted November 15, 2004 Administrators Posted November 15, 2004 What spec PC are you running this on? Just cut and pasted yuor code and it was only taking approx 90ms, although if you don't create the size and font on each itteration of the loop I managed to cut about 20ms off the time. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
shizon Posted November 15, 2004 Author Posted November 15, 2004 I'm running it on my laptop which is 1.6 Centrino. I guess I should also add that this is being developed for a smart application so I'm running it in the ce.net emulator. Also, I stuck a msgbox at the end of the for next to show me the time and it hits the msgbox before it's done drawing the buttons. I don't think it's a code related issue, but more a factor of drawing the buttons. I'd say it takes about 1/2 a second, maybe a little more, to draw them. I also tested by creating another button that hides and then shows the buttons and I get no delay whatsoever. I also did some more research and found some other talk about .NET being slow to draw controls, especially over 50. I heard from somewhere, don't remember where, that you can use bitblt to help this somehow. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.