Re: Scrolling text in a stationary label help needed
- From: jcrouse1@xxxxxxxxxxx
- Date: 20 Sep 2006 04:52:19 -0700
Mike,
Thanks a lot for your time on this. It really is appreciated.
Anyways, the above code doesn't work for me. I haven't looked at it in
depth yet but will in a few hours. ALso, I am using the code with the
timer, since I need to continue execution. Anyways, any idea on my
transparency issue in my last post. It is why I was attempting to use a
label in the first place.
Thanks,
John
Mike Williams wrote:
<jcrouse1@xxxxxxxxxxx> wrote in message
news:1158715983.824151.230330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Second, I am trying to figure out how to have the text exit the
left side of the picturebox before it starts scrolling on the right
side again. I am trying to somehow replace the "space$(12)"
in the following example with . . . . .
Using the TextWidth function to get your values you can simply divide the
TextWidth of the entire string by the TextWidth of a single space character.
That will tell you how many spaces take up the same length as the string.
You then add the required number of spaces to the string. However, there is
another way of achieving what you are after which does not require you to do
that and which actually makes the scrolling loop code a little simpler.
Perhaps an explanation of how the existing method works will help:
At the moment the first time the string is printed into the Picture box it
is printed at x coordinate zero (using Picture1.CurrentX to set the x
coordinate).
When the time comes to move the string to the left by one pixel the
following happens. For this explanation we'll assume that the string to be
scrolled is "Rum and Coke" (with no spaces just to make the explanation a
little easier to understand).
1. Any existing displayed text is cleared using the Cls method.
2. The x coordinate is decremented (it goes from zero to minus 1)
3. The string is printed again at the new x coordinate.
This causes VB to print the string a little to the left, with the "unprinted
pixels" that fall to the left of zero simply being clipped (because they are
outside the left edge of the picture box).
The above sequence is repeated (x = 0, x = -1, x = -2, x = -3, etc) until we
reach a point where the negative value of x is greater in magnitude than the
pixel width of the leftmost character in the string ("R"). At this point we
change the actual string itself, by "chopping off" its current leftmost
character and adding it at the end. In other words, at this point the
original string of (say) "Rum and Coke" becomes (um and CokeR). We then set
the x coordinate back to zero before printing the new string.
The above sequence is then repeated with the new string, each time
decrementing the x coordinate by 1, until we again reach the point where the
negative value of x is greater in magnitude than the "new first character"
of the string ("u"). We then again change actual string by chopping off the
current first character and adding it to the end. This time we end up with
"m and CokeRu" (remember, to simplify things for the explanation just so
that you can more easily see the result in a printed newsgroup posting we
are using a string with no trailing space characters). We again set the x
coordinate back to zero and proceed as before. The above stuff simply loops
over and over again until we decide to stop it.
If you want to do it slightly differently (so that the entire string rolls
off to the left before it starts to appear again at the right) you can
simply calculate and add sufficient space characters at the right of the
string that are equal in TextWidth to the string itself, as I suggested at
the start of this reply. However, for such a display there is an easier way
of doing it (easier to understand, that is). All you need to do is to
initially display the string at an x coordinate with a positive value that
is equal to the pixel width of the picture box, and each time you want to
scroll left by a pixel you decrement the x coordinate by 1 and display the
string again, but this time instead of stopping when you reach a value with
a magnitude greater than the width of the first character you simply keep on
decrementing the x coordinate (which initially started with a positive value
equal to the width of the picture box) and you keep decrementing it, passing
through zero and continuing to decrement it until the negative x coordinate
is equal in magnitude to the pixel width of the entire string. You then
start again by setting the x coordinate to a positive value equal to the
pixel width of the picture box. This method is simpler because at no point
does it require you to mess about "chopping characters off from the left and
adding them to the right" of the string. You just leave the string exactly
in its original state at all times.
Here's an example.
Mike
Option Explicit
Private objDX As New DirectX7
Private objDD As DirectDraw7
Private Sub Form_Load()
Set objDD = objDX.DirectDrawCreate("")
Me.Picture = LoadPicture("c:\tulips.jpg")
End Sub
Private Sub Scroll(x As Long, y As Long, _
picwide As Long, pichigh As Long)
Dim stext As String
Dim wide As Long, xposition As Long
Me.ScaleMode = vbPixels
Me.Width = Screen.Width * 0.9
With Picture1
.Visible = False
.BorderStyle = vbBSNone
.BackColor = RGB(123, 156, 189)
.AutoRedraw = True
.ScaleMode = vbPixels
.FontName = "Times New Roman"
.FontSize = 16
.FontBold = True
.ForeColor = vbBlue
.Cls
stext = "A simple demonstration of some horizontally "
stext = stext & "scrolling text in a picture box."
.Move x, y, picwide, pichigh
DoEvents
.PaintPicture Me.Picture, 0, 0, picwide, pichigh, _
x, y, picwide, pichigh
.Picture = .Image
.Visible = True
End With
wide = Picture1.TextWidth(stext)
Do
For xposition = picwide To -wide Step -1
Picture1.Cls
Picture1.CurrentX = xposition
Picture1.Print stext;
objDD.WaitForVerticalBlank DDWAITVB_BLOCKBEGIN, ByVal 0
DoEvents
Next xposition
Loop
End Sub
Private Sub Command1_Click()
Scroll 100, 200, 500, 24
End Sub
.
- Follow-Ups:
- Re: Scrolling text in a stationary label help needed
- From: Mike Williams
- Re: Scrolling text in a stationary label help needed
- References:
- Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: Dmitriy Antonov
- Re: Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: Dmitriy Antonov
- Re: Scrolling text in a stationary label help needed
- From: Mike and Maureen
- Re: Scrolling text in a stationary label help needed
- From: Mike Williams
- Re: Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: jcrouse1
- Re: Scrolling text in a stationary label help needed
- From: Mike Williams
- Scrolling text in a stationary label help needed
- Prev by Date: Re: Seeing DLL code in different VB instance
- Next by Date: Re: MS: Vista Apps Must Be 'Cool'
- Previous by thread: Re: Scrolling text in a stationary label help needed
- Next by thread: Re: Scrolling text in a stationary label help needed
- Index(es):
Relevant Pages
|