From: Webbiz on
Thanks Larry. :-)

This code is very instructional.

Best regards,

Webbiz



On Mon, 23 Nov 2009 17:04:08 -0600, "Larry Serflaten"
<serflaten(a)usinternet.com> wrote:

>
>"Webbiz" <nospam(a)forme.thanks.com> wrote
><...>
>> Currently, I can scroll this chart by either double-clicking the
>> chart, holding down the mouse button on the second click, and dragging
>> the mouse to a new location. After the mouse is let up, then the draw
>> is redrawn in the new location.
><...>
>> With the arrow keys, in order to show the chart actually scrolling, it
>> runs the DrawChart and RedrawTools over and over, one day (bar) at a
>> time. This looks really rickety, and moves so slow. Watching it redraw
>> each time is a flickering hodge-podge. It would be nice if the chart
>> would scroll smoothly and quickly.
><...>
>> Any suggestions, tips and otherwise?
>
>
>As other have said, using a second buffer is going to help.
>
>Do remember that your whole application is just so many pixels on
>a screen. As long as you can draw something that looks like a chart,
>people will believe its a chart. If you can draw something that looks
>like a button, people will believe its a button, until shown otherwise.
>
>One method to help reduce the flicker would be to draw the whole
>chart to an invisible picturebox, and then just show what you need
>to fill the form area.
>
>For an example, add a picturebox to a new form and paste in the
>code below....
>
>As posted it only handles the mouse drag operation, I've left it up
>to you to handle the others.
>
>HTH
>LFS
>
>
>Option Explicit
>Private imgLeft As Long
>Private MX As Single
>
>Private Sub Form_Load()
>Dim X
>' Draw chart
> Picture1.BorderStyle = vbBSNone
> Picture1.Move 0, 0, 30000, 4000
> Picture1.AutoRedraw = True
> Picture1.BackColor = vbWhite
> Picture1.Line (90, 90)-(29780, 3920), vbBlack, B
> For X = 105 To 29800 Step 900
> Picture1.PSet (X, 90), vbBlack
> Picture1.Line -Step(0, 3810), &HCCCCCC
> Picture1.PSet (X + 30, 1600), vbWhite
> Picture1.Print CStr(X \ 90 - 1)
> Next
> Me.Move 1000, 1000, 8000, 4600
> Picture1.Visible = False
>End Sub
>
>Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
> MX = X
>End Sub
>
>Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
> If Button = vbLeftButton Then
> imgLeft = imgLeft + (X - MX)
> ' Test boundries
> If imgLeft > 0 Then imgLeft = 0
> If imgLeft < (Me.Width - Picture1.Width) Then imgLeft = (Me.Width - Picture1.Width)
> MX = X
> ' Paint chart
> PaintPicture Picture1.Image, imgLeft, 0
> End If
>End Sub
>
>Private Sub Form_Paint()
> PaintPicture Picture1.Image, imgLeft, 0
>End Sub
>
From: Dave O. on

"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:lfolg51dqo43v288g7k8v7ahd7fv5f2gce(a)4ax.com...
> Hello.
>
> An old project of mine draws stock charts on a picturebox called
> pctChart.
>
> On this pctChart, a routine called DrawChart is used to draw OHLC or
> Candlestick price bars.
>
> After the bars are drawn, the chart tools are drawn over them, such as
> lines, boxes, etc. This is done in RedrawTools.
>
> Currently, I can scroll this chart by either double-clicking the
> chart, holding down the mouse button on the second click, and dragging
> the mouse to a new location. After the mouse is let up, then the draw
> is redrawn in the new location.
>
> Or, I can press and hold the Left or Right arrow keys and it will
> scroll the chart (slowly) to the right or left.
>
> Problem:
>
> With the arrow keys, in order to show the chart actually scrolling, it
> runs the DrawChart and RedrawTools over and over, one day (bar) at a
> time. This looks really rickety, and moves so slow. Watching it redraw
> each time is a flickering hodge-podge. It would be nice if the chart
> would scroll smoothly and quickly.
>
> As for scrolling with the mouse, I'd like it to actually show the bars
> scrolling, also smoothly and as quick as the mouse is being moved,
> while the mouse is being moved. Right now, I don't do any of the
> redraw with the mouse until it has stopped at the new location,
> because of the flickering issue. There is just all these redraws.
>
> Because I have purchased programs that seem to do this without any
> problem, I believe it should be possible to do the same with my
> project. Yet, I'm wondering if this is a VB6 problem, and that I'd
> have to program with C to achieve the above.
>
> And yes, I have a decently quick computer and graphics card, so that's
> not the problem.
>
> Any suggestions, tips and otherwise?
>
> Thanks.
>
> Webbiz

If all you want to do is move the image about when scrolled another option
is to put a very big picture box inside a much smaller picture box, plot
your stuff on the large one then with scroll bars you can move the whole box
but only the part visible through the smaller box would be seen.

Dave O.


From: Nobody on
"Dave O." <nobody(a)nowhere.com> wrote in message
news:%232QL0pObKHA.5544(a)TK2MSFTNGP02.phx.gbl...
> If all you want to do is move the image about when scrolled another option
> is to put a very big picture box inside a much smaller picture box, plot
> your stuff on the large one then with scroll bars you can move the whole
> box but only the part visible through the smaller box would be seen.

The sample that Larry Serflaten posted did just that, except he used a large
PictureBox and the form.


From: Larry Serflaten on

"Webbiz" <nospam(a)forme.thanks.com> wrote
> Thanks Larry. :-)
>
> This code is very instructional.

You're welcome. However, typical for one-off replies, there was a line that
needs replacement:

If imgLeft < (Me.Width - Picture1.Width) Then imgLeft = (Me.Width - Picture1.Width)

Because different people have different form borders, that Me.Width
should have been Me.ScaleWidth, with the apporpreate adjustments to
the boundry checks....

Have fun!
LFS


From: Mike Williams on
"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:to9mg59copm54b0iiscqtupri01q4khaik(a)4ax.com...

> Drawing the whole picturebox each time.

Right. In that case perhaps you might like to consider drawing it just once
into an offscreen Autoredraw PictureBox and painting or positioning only the
required part into the display as you scroll, as has already been suggested
by Dave and Larry.

I do seem to vaguely recall you posting something about your stock chart
drawing program a long time ago and saying that there was a reason you could
not do that when I suggested it at the time, but I can't remember what that
reason was now. Was there a specific reason that you could not do that,
something to do with the data changing on the fly or something? I can't
remember now. If not then it certainly is a good way of doing it, and you
will be able to use more than one offscreen PictureBox to predraw a very
large amount of data, perhaps about 30 or 40 screen widths of data, before
you begin to eat too much into the RAM available for other applications, and
much more than that if you use DIBs instead of PictureBoxes or other screen
compatible bitmaps, because DIBs will quite happily live in the swapfile.

> Mostly, I use the Picturebox.Line method. Just drawing
> a line from here to there, here to there, here to there.

The PictureBox Line method is about as fast as the alternative API MoveTo /
LineTo method (which is understandable of course because that's what it uses
under the hood), but the only problem is that (as with all native VB drawing
methods) it effectively triggers a Refresh on an Autoredraw PictureBox,
which is somehting that you often do not want. But as far as actual drawing
speed is concerned it is much the same. One thing to note is that according
to the video you posted you are using lines more than one pixel wide. These
are drawn slower than single pixel lines of course, but in Vista (which
disables the video card's accelerated GDI hardware) the speed is comparable
with drawing more than one separate single pixel line (although this was not
the case in XP as I recall, which does use the video card's accelerated GDI
functions and in which the drawing of single pixel thick lines was
blindingly fast). In Vista, also, the speed of the different GDI drawing
functions is affected by whether or not the system is currently running at
the "disable desktop composition" setting, but generally it is faster to
draw horizontal or vertical lines of more than one pixel thickness using the
API FillRect function rather than the API LineTo function (or the VB Line
method). The amount of extra speed you get from using FillRect is not a lot
when Vista is running its standard Aero desktop, and is much more when Vista
is running in "disable desktop composition" mode, but in all cases (in
Vista) it is faster than LineTo, at least on the systems I've personally
tried it on. In XP things were very different of course, but the Win32 GDI
is now effectively crippled on almost all Vista machines. How sad :-(

> [in respnse to a statement regarding the keyboard repeat
> rate] Ah...no. I'm not that sophisticated, remember. :-0

You can overcome that by creating a keymap in memory (a simple array) and
using a Key event to set the curreent state of the keys as they are pressed
and released by the user. In that way your code can examine the key map at
any time you wish and you will know whether any specific key is currently
down or up. So, instead of using an arrow key event to scroll your image you
can use a timer or a code loop to repeatedly react to the current state of
the required key.

Mike



First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9
Prev: Snapshot of screen
Next: HTTPS File Uploads