Re: Horizontal ScrollBar+ PictureBox + Flickering (how to stop flickering?)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Frank Moyles" <fgmoyles@xxxxxxxxxx> wrote
I have a PictureBox placed on a form, as well as a horizontal scroll
bar. I am drawing a graph (output from an instrument) on the PictureBox.

I am 'scrolling' the graph by dragging the horizontal scroll bar. Each
time the scroll bar changes, I am getting the new values and using that
event to redraw the graph - it works in theory, but in practise, it
flickers quite a lot.

Is there anyway I can eliminate the flickering as I move the scrollbar -
and simply have a "smoothly scrolling" picture as I drag the scrollbar?

How about making the picturebox large enough to hold the entire graph,
and then move the picturebox via the scrollbar events?

For an example, add a Picturebox and HScroll bar to a new form and
paste in the code below....

LFS


Option Explicit

Private Sub Form_Load()
Dim X As Long, c As Long
Picture1.Move 0, 0, 120000, 2000
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0
Picture1.PSet (-1, 1000), vbBlack
Picture1.DrawWidth = 3
For X = 0 To Picture1.Width Step 195
c = c + 1
If c > 50 Then
Picture1.ForeColor = QBColor(Int(Rnd * 16))
c = 0
End If
Picture1.Line -(X, 1000 + Sin(X) * 900)
Next
HScroll1.Min = 0
HScroll1.Max = (Picture1.Width - ScaleWidth) / 100
HScroll1.Move 0, 2120, ScaleWidth, 240
HScroll1.SmallChange = 1
HScroll1.LargeChange = ScaleWidth / 100
End Sub

Private Sub Form_Resize()
HScroll1.Max = (Picture1.Width - ScaleWidth) / 100
HScroll1.Move 0, 2120, ScaleWidth, 240
End Sub

Private Sub HScroll1_Change()
HScroll1_Scroll
End Sub

Private Sub HScroll1_GotFocus()
Picture1.SetFocus
End Sub

Private Sub HScroll1_Scroll()
Picture1.Move CLng(HScroll1.Value) * -100
End Sub


.



Relevant Pages

  • Re: Plotting points in picturebox
    ... The image itself is a pre-made graph with the X,Y axis starting ... > coordinate in the picturebox. ... Private Sub DrawGraph(ByVal MinX, ByVal MaxX, ByVal MinY, ByVal MaxY) ...
    (microsoft.public.vb.general.discussion)
  • Re: Date picker scrollbar month and year only
    ... Or put a button on those userforms that pops up a very small userform with just ... Private Sub CommandButton1_Click ... You gave me the directions for the date scrollbar displaying month/year ... "Dave Peterson" wrote: ...
    (microsoft.public.excel.misc)
  • Re: "Scrolling with Scrollbar or SpinButton on UserForm"
    ... How do I code this scrollbar so that it opens on the last value? ... Here's what I've done so that the scrollbar has an open blank cell at the ... Private Sub UserForm_Initialize ...
    (microsoft.public.excel.programming)
  • Re: multiple scroll areas on sheet?? and combo box values
    ... Private Sub ScrollBar1_Change ... Scroll the scrollbar and see the effect. ... Enable the combo in the Workbook_Open event, populate the ... > I also have many combo boxes. ...
    (microsoft.public.excel.programming)
  • RE: Excel VBA Userforms - especially check boxes
    ... Private Sub CommandButton1_Click ... It would be hard to say anything about the scrollbar - if the event doesn't ... If I tick a checkbox I want Excel to put TRUE in the ... corresponding cell. ...
    (microsoft.public.excel.programming)