-
[RESOLVED] How to make some words move up to down or down to up?
I wonder how to make some words or sentences move up to down or down toup in VB 6.0 ?
Any one have some hints?
Thank u
-
Re: How to make some words move up to down or down to up?
Not sure what you mean. :confused:
Do you mean something like SUPERSCRIPT or SUBSCRIPT ?
-
Re: How to make some words move up to down or down to up?
For example, I am doing a game, and in Manual showing how to play, I want the sentences display slowly from up to down.
-
Re: How to make some words move up to down or down to up?
use the Timer to change the sentences 's position
-
Re: How to make some words move up to down or down to up?
But how, because I never use Timer before. Can u show me one example?
-
Re: How to make some words move up to down or down to up?
Here is an example of auto scrolling with RichTextBox using EM_GETSCROLLPOS and EM_SETSCROLLPOS messages. You can control speed by changing the timer's interval or by changing the VSCROLL_SPEED constant's value
(Scrolling using TextBox is easier, but it is 'jerky')
Also search the forum for "RichTextBox Scroll" or "TextBox Scroll" or similar phrase. There are many threads on this topic.
VB Code:
' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
Option Explicit
Private Type POINT
X As Long
Y As Long
End Type
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32.dll" _
(ByVal hwndLock As Long) As Long
Private Const WM_USER As Long = &H400
Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
'
Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
'
Dim MaxPos As POINT
Dim CurrentPos As POINT
'----------------------------------------------------------------------
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 20 'Use it to control speed
'
Dim i As Long
Dim BlnkLines As Long
RichTextBox1.Text = ""
'
' add blank lines at top -->
BlnkLines = RichTextBox1.Height / Me.TextHeight("|")
RichTextBox1.SelStart = 0
RichTextBox1.Font = Me.Font
'
For i = 1 To BlnkLines
RichTextBox1.Text = RichTextBox1.Text & vbCrLf
Next
'
' insert Test text -->
For i = 1 To 50
RichTextBox1.Text = RichTextBox1.Text & vbCrLf & "Line - " & i
Next
End Sub
'----------------------------------------------------------------------
Private Sub Command1_Click()
'Get maximum value for scrolling ---->
LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
RichTextBox1.SelStart = Len(RichTextBox1.Text)
Call SendMessage(RichTextBox1.hwnd, EM_GETSCROLLPOS, 0, MaxPos)
LockWindowUpdate 0
'
'Set scroll position at begining ---->
CurrentPos.X = 0
CurrentPos.Y = 0
Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
'
Timer1.Enabled = True
End Sub
'----------------------------------------------------------------------
Private Sub Timer1_Timer()
If CurrentPos.Y <= MaxPos.Y Then
CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
Else
CurrentPos.Y = MaxPos.Y
Timer1.Enabled = False
End If
End Sub
-
Re: How to make some words move up to down or down to up?
I tried already, but i am using VB6, there is no richtextbox, so can you tell me how to do with Textbox however it is jerky or whatever. I just want to learn how to do.
Thank you
-
Re: How to make some words move up to down or down to up?
VB6 comes with RichTextBox. :)
Open VB. Start a new project.
Press Ctrl+T. It will bring the 'Components' window.
From the list, select and check "Microsoft RichTextBox Control".
Click OK.
Now, in the toolbox, you'll find RichTextBox's icon.
Draw it in the form just like any other control.
-
Re: How to make some words move up to down or down to up?
OK, it works well. But can I do it with Label?
-
Re: How to make some words move up to down or down to up?
Quote:
Originally Posted by emotions
OK, it works well. But can I do it with Label?
No, because Labels do not have .Hwnd property which is a required parameter of SendMessage API.
-
Re: How to make some words move up to down or down to up?
You can. But if you have variable length text, it will take a little more effort. (You'll need to accomodate the text in the label using code.)
If the text is fixed, just place (draw) the label in a picturebox. Make it long enough to hold your full text. Then resize the container picturebox to hide 'at-first-invisible' porton of the label.
Now, from the timer, use the label's Top property to move it.
Edit: As Harsha mentioned, SendMessage will not work with labels. It will be a completely different code.
-
Re: How to make some words move up to down or down to up?
you could do it with a picturebox:
VB Code:
Private Sub Timer1_Timer()
Static lX As Long
Picture1.Cls
Picture1.CurrentX = lX
Picture1.Print "Line1" & vbCrLf & "Line2" & vbCrLf & "Line3"
lX = lX - 1
End Sub
not sure how pretty it'd be though
-
Re: How to make some words move up to down or down to up?
@Bushmobile,
[NotTested] but I think in this case the picturebox will flicker a lot.
-
Re: How to make some words move up to down or down to up?
thank you so much for your help. But there is still one thing I want to know that: If doing in your way, use Richtextbox, so we have to type something in the richtextbox after press the Button. For me, I prefer like that: when we Run the program, the Richtextbox must be clear, then after we click on the Button, some texts will be shown from the bottom to top.
How to make it?
Anyone has some hint?
Does it look like better right?
-
Re: How to make some words move up to down or down to up?
Just like textbox, RTB has a .Text property.
VB Code:
RichTextBox1.Text = "" ' clear text
RichTextBox1.Text = "Blah Blah" ' some text
Here is a RTB tutorial. I hope it will help you.
-
Re: How to make some words move up to down or down to up?
I meant we typed some texts first, then after click on the command button, those text will come out from bottom to top.
Sorry for my English,:)
-
Re: How to make some words move up to down or down to up?
Sorry, I skipped part of your post.
For the 'blank at first effect',
you can add blank lines before your original text.
or,
Add a picturebox and change its backcolor to white. Place the RTB inside this picture control. The picbox will be RTB's Container.
Then at designtime resize the picturebox so that the RTB isn't visible.
Now inside the timer, first move the whole RTB. When the RTB reaches top of the picturebox, start original scrolling code.
-
Re: How to make some words move up to down or down to up?
Sorry but I dont understand your means. So can you explain more because I tried to follow your way, but it seems does not want to do :(
-
Re: How to make some words move up to down or down to up?
I've edited the code in post#6. Try it.
-
Re: How to make some words move up to down or down to up?
very nice but where will I add my text for example is paragraph
-
Re: How to make some words move up to down or down to up?
I would recommend you save the text in a file. Plain text file - if you don't need special formatting, or as rtf file if you need formatting.
You can load this file at designtime. Rightclick the RTB, select properties. In the new window, select the filename.
or,
at runtime, you can use the .LoadFile() method to load the file. (See MSDN for more explation)
VB Code:
RTB1.LoadFile "C:\aaa.rtf"
-
Re: How to make some words move up to down or down to up?
But when it loads the text file, those blank lines are not effected.
-
Re: How to make some words move up to down or down to up?
And also the texts do not stop on the top, it runs over and disappears
-
Re: How to make some words move up to down or down to up?
Quote:
But when it loads the text file, those blank lines are not effected.
You first load the file and then insert blank lines.
Quote:
And also the texts do not stop on the top, it runs over and disappears
Really ? The scrolling should stop when the RTB reaches bottom of the vritual text space. :confused:
-
Re: How to make some words move up to down or down to up?
What do u mean is first loading the file and then inserting blank lines? I tried but it did not work at all.
Can you try and show me the codes?
-
Re: How to make some words move up to down or down to up?
And one thing is why i have already inserted Rich Text Box but when I re-open VB again, the RTB disappear and I have to insert again.
Is there another way can insert RTB forever?
-
RichtextBox Auto Scroll
Quote:
Originally Posted by emotions
What do u mean is first loading the file and then inserting blank lines? I tried but it did not work at all.
Can you try and show me the codes?
Here is a slightly modified version. Try this.
VB Code:
' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
Option Explicit
Private Type POINT
X As Long
Y As Long
End Type
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32.dll" _
(ByVal hwndLock As Long) As Long
Private Const WM_USER As Long = &H400
Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
'
Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
'
Dim MaxPos As POINT
Dim CurrentPos As POINT
'----------------------------------------------------------------------
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 20 'Use it to control speed
End Sub
'----------------------------------------------------------------------
Private Sub Command1_Click()
PrepareRTB
'Get maximum value for scrolling ---->
LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
RichTextBox1.SelStart = Len(RichTextBox1.Text)
Call SendMessage(RichTextBox1.hwnd, EM_GETSCROLLPOS, 0, MaxPos)
LockWindowUpdate 0
'
'Set scroll position at begining ---->
CurrentPos.X = 0
CurrentPos.Y = 0
Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
'
Timer1.Enabled = True
Me.Caption = "Scrolling Started"
End Sub
'----------------------------------------------------------------------
Private Sub Timer1_Timer()
If CurrentPos.Y <= MaxPos.Y Then
CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
Else
CurrentPos.Y = MaxPos.Y
Timer1.Enabled = False
Me.Caption = "Scrolling Ended"
End If
End Sub
'----------------------------------------------------------------------
Private Sub PrepareRTB()
'
Dim i As Long
Dim BlnkLines As Long
With RichTextBox1
.Text = ""
' Load a file -->
.LoadFile [color=maroon]"C:\SomeFile.rtf"[/color]
'
' add blank lines at top -->
BlnkLines = .Height / Me.TextHeight("|")
.SelStart = 0
.SelFontName = Me.Font.Name
.SelFontSize = Me.Font.Size
.SelBold = False
For i = 1 To BlnkLines
.SelText = vbCrLf
Next
'
' [b]If you want the text to disappear after scrolling, uncomment following block[/b]
''' ' add blank lines at bottom -->
''' .SelStart = Len(.Text)
''' .SelFontName = Me.Font.Name
''' .SelFontSize = Me.Font.Size
''' .SelBold = False
'''
''' For i = 1 To BlnkLines
''' .SelText = vbCrLf
''' Next
End With
End Sub
Quote:
Originally Posted by emotions
And one thing is why i have already inserted Rich Text Box but when I re-open VB again, the RTB disappear and I have to insert again.
Is there another way can insert RTB forever?
I don't know if there is any way to to edit the default project template.
Here is an alternative,
Open a new standard exe project.
add a RTB in the form.
Rename the form as "frmRTB".
Save the form in <Visual Studio Folder>\VB98\Template\Forms folder.
Close and reopen VB.
Start a new project.
Click Project>Add Form menu.
In the 'new' tab, you'll see our frmRTB.
Add it in your project and use it.
Similarly, you can store store any other template projects/forms/controls etc in \VB98\Template\??? folders.
-
Re: How to make some words move up to down or down to up?
it worked well but non-stop. I meant the text keeps going and after that disappears instead of stopping.
I need it stops at the top
-
Re: How to make some words move up to down or down to up?
May be this time it will work :p
VB Code:
' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
Option Explicit
Private Type POINT
X As Long
Y As Long
End Type
Private Declare Function SendMessage Lib "user32.dll" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any) As Long
Private Declare Function LockWindowUpdate Lib "user32.dll" _
(ByVal hwndLock As Long) As Long
Private Const WM_USER As Long = &H400
Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
'
Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
'
Dim MaxY As Long
Dim CurrentPos As POINT
'----------------------------------------------------------------------
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 20 'Use it to control speed
End Sub
'----------------------------------------------------------------------
Private Sub Command1_Click()
PrepareRTB
Timer1.Enabled = True
Me.Caption = "Scrolling Started"
End Sub
'----------------------------------------------------------------------
Private Sub Timer1_Timer()
If CurrentPos.Y <= MaxY Then
CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
Else
CurrentPos.Y = MaxY
Timer1.Enabled = False
Me.Caption = "Scrolling Ended"
End If
End Sub
'----------------------------------------------------------------------
Private Sub PrepareRTB()
Dim i As Long
Dim BlnkLines As Long
With RichTextBox1
.Text = ""
LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
.LoadFile "C:\SomeFile.rtf" ' Load a file
'----------------------------------
' add blank lines at top -->
BlnkLines = .Height / Me.TextHeight(" ")
.SelStart = 0
.SelFontName = Me.Font.Name
.SelFontSize = Me.Font.Size
.SelBold = False
For i = 1 To BlnkLines
.SelText = vbCrLf
Next
'----------------------------------
MaxY = (.Height / Screen.TwipsPerPixelY) - 6 ' (-6) pixel is for the border)
LockWindowUpdate 0
'----------------------------------
'Set scroll position at begining ---->
CurrentPos.X = 0
CurrentPos.Y = 0
Call SendMessage(.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
End With
End Sub
-
Re: How to make some words move up to down or down to up?
Finally, it works very well. Thanks a lot. Vote for you 5 starts :)
-
Re: How to make some words move up to down or down to up?
Quote:
Originally Posted by emotions
Finally, it works very well. Thanks a lot. Vote for you 5 starts :)
That's rating for THIS thread. :bigyello:
To rate a member click tke "Rate this post" link below their username and in the new window select "approve" to rate him/her +ve or select "Don't approve" to rate -ve. :wave: