-
May 11th, 2021, 11:49 PM
#1
Thread Starter
New Member
Large Listbox Causing Performance Issues & Avoid Control Flickerings
I need help, as soon as possible. I want to finish this project and these are the only issues I'm having with the project.
PERFORMANCE ISSUE: Good morning, so I'm using a custom a tab control which was not coded personally and within the second tab there's a listbox. I have two tabs(password generator, and password list). Upon switching to the second time for the first time, it will render the tab and when you go back to first tab(password generator) to generate passwords which is adding items to the listbox in second tab(password list) the performance will start to decrease fast. If you just open the program on the first run and don't go to second tab(to render the listbox), it will not decrease in performance when adding items, it will work perfectly actually, There's a 90% chance the performance has nothing to do with the tab control than it does with the flickering but i'm just mentioning, but I tried turning DoubleBuffer on & off for the for the main form and tried doing research but I can not find anything working. Not to mention when generating passwords it adds items to five other listboxes and an array but they are not visible so I doubt they affect the performance & it's been doing this before I even made the other five listboxes. How can this fix this?
RANDOM FLICKERING: Okay, When switching tabs, the form will flicker, I have one visible listbox on my form which is within a custom tab control in the second tab, when adding items to the listbox, it will update the tab control title, the button to generate passwords when the mouse is press down it will execute a function which updates the tab control title and will start a timer to generate the password until the mouse is released, so the tab control title is constantly updating, it will occasionally flicker. The listbox will flicker when when i open another form too, i'm trying to have my application as smooth as possible. How can i stop this?
Tab Control Title Update:
Code:
Tab2.Text = "Password List " & "[" & PasswordList.Items.Count().ToString("N0") & "]"
Tab Control:
Code:
Public Class AnimTab
Inherits TabControl
Dim OldIndex As Integer
Private _Speed As Integer = 25
Property Speed As Integer
Get
Return _Speed
End Get
Set(value As Integer)
If value > 25 Or value < -25 Then
If Not Application.OpenForms().OfType(Of notificationForm).Any Then
notificationForm.Text = "Password List"
notificationForm.setText.Text = "Choose Value At Least or Below 20."
notificationForm.Show()
Else
notificationForm.s = 0
notificationForm.ml = 60
notificationForm.FadeOUT.Stop()
notificationForm.FadeIN.Start()
notificationForm.Opacity = 0
notificationForm.Text = "Password List"
notificationForm.setText.Text = "Choose Value At Least or Below 20."
notificationForm.Show()
End If
Else
_Speed = value
End If
End Set
End Property
Sub New()
SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw, True)
End Sub
Sub DoAnimationScrollLeft(ByVal Control1 As Control, Control2 As Control)
Dim G As Graphics = Control1.CreateGraphics()
Dim P1 As New Bitmap(Control1.Width, Control1.Height)
Dim P2 As New Bitmap(Control2.Width, Control2.Height)
Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))
For Each c As Control In Control1.Controls
c.Hide()
Next
Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)
Dim a As Integer
For a = 0 To Slide Step _Speed
G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))
Next
a = Control1.Width
G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
G.DrawImage(P2, New Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height))
SelectedTab = Control2
For Each c As Control In Control2.Controls
c.Show()
Next
For Each c As Control In Control1.Controls
c.Show()
Next
End Sub
Protected Overrides Sub OnSelecting(e As System.Windows.Forms.TabControlCancelEventArgs)
If OldIndex < e.TabPageIndex Then
DoAnimationScrollRight(TabPages(OldIndex), TabPages(e.TabPageIndex))
Else
DoAnimationScrollLeft(TabPages(OldIndex), TabPages(e.TabPageIndex))
End If
End Sub
Protected Overrides Sub OnDeselecting(e As System.Windows.Forms.TabControlCancelEventArgs)
OldIndex = e.TabPageIndex
End Sub
Sub DoAnimationScrollRight(ByVal Control1 As Control, Control2 As Control)
Dim G As Graphics = Control1.CreateGraphics()
Dim P1 As New Bitmap(Control1.Width, Control1.Height)
Dim P2 As New Bitmap(Control2.Width, Control2.Height)
Control1.DrawToBitmap(P1, New Rectangle(0, 0, Control1.Width, Control1.Height))
Control2.DrawToBitmap(P2, New Rectangle(0, 0, Control2.Width, Control2.Height))
For Each c As Control In Control1.Controls
c.Hide()
Next
Dim Slide As Integer = Control1.Width - (Control1.Width Mod _Speed)
Dim a As Integer
For a = 0 To -Slide Step -_Speed
G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))
Next
a = Control1.Width
G.DrawImage(P1, New Rectangle(a, 0, Control1.Width, Control1.Height))
G.DrawImage(P2, New Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height))
SelectedTab = Control2
For Each c As Control In Control2.Controls
c.Show()
Next
For Each c As Control In Control1.Controls
c.Show()
Next
End Sub
End Class
-
May 12th, 2021, 12:49 AM
#2
Re: Large Listbox Causing Performance Issues & Avoid Control Flickerings
There is an article that seems to fix the issue but is in C#, haven't tried
http://yacsharpblog.blogspot.com/200...x-flicker.html
Personally I am using an extension method to double buffer the listview and always do BeginUpdate - Endupdate.
Here is what I do.
Code:
Module ControlExtensions
<Extension()>
Sub DoubleBuffered(ByVal control As Control, ByVal enable As Boolean)
Dim doubleBufferPropertyInfo = control.[GetType]().GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
doubleBufferPropertyInfo.SetValue(control, enable, Nothing)
End Sub
End Module
And on form load MyListView.DoubleBuffered(True)
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
May 13th, 2021, 03:12 PM
#3
Re: Large Listbox Causing Performance Issues & Avoid Control Flickerings
Don't add your items individually. Every time you add to the ListBox it's redrawn. if you don't open your second tab, performance is better because, graphically, the controls on the second tab haven't been created. Add your items to a List(Of String), then use AddRange on the ListBox after the operation is completed.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|