I have a "time line" in my application, consisting of many labels (dynamic) that get placed according to their relative position in the time scale.
I have another section below this, which is the "legends" section for the time line. When hovering over a particular legend, I step through the time line, and set all the non relevant labels to visible = false
, and the relevant labels to visible
. This allows the user to hover over a certain legend label, and see it represented alone on the time line.
Extra Info When a user exits the legend(label) hover, I restore all the lines (labels) on the timeline to visible. /Extra info
This all works really well, but some of my time scales, have 800+ labels on them (thin lines).
The interface updates in about 3-5 seconds in this case, which is acceptable, but the CPU REALLY battles to keep up.
When testing, my music player stutters big time whenever I run this code to interact with the time line. As soon as the loop is finished, the cpu catches up again.
As I really don't want to use a doEvents()
(not that it really helps.. I tried), what other suggestions can you offer to give the cpu some breathing time.
What I have done so far:
My code:
Private Sub label_hovered(appname As String) Handles myAwesomeViewLegend.labelHover
Try
blockPanel.Visible = False
For Each l As Label In blockPanel.Controls
If l.Text = appname Then
l.Visible = True
Else
l.Visible = False
End If
Next
blockPanel.Visible = True
Catch ex As Exception
Dim method_name As String = System.Reflection.MethodBase.GetCurrentMethod().Name
Dim method_class As String = System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.FullName
MsgBox(ex.tostring & vbcrlf & vbcrlf & method_name & vbcrlf & vbcrlf & method_class)
End Try
End Sub
答案 0 :(得分:1)
I would construct only the visible labels. I think it is a bad practice creating 800 labels and toggle the Visibility
property.
Create a sorted list with times and check if a time should be visible by calculating the start and endtime (window). Create labels for the (should be visible) times.