Results 1 to 31 of 31

Thread: [RESOLVED] How to make some words move up to down or down to up?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    Resolved [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

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to make some words move up to down or down to up?

    Not sure what you mean.

    Do you mean something like SUPERSCRIPT or SUBSCRIPT ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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.

  4. #4
    New Member
    Join Date
    Aug 2006
    Posts
    2

    Re: How to make some words move up to down or down to up?

    use the Timer to change the sentences 's position

  5. #5

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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?

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. ' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
    2. Option Explicit
    3.  
    4. Private Type POINT
    5.   X As Long
    6.   Y As Long
    7. End Type
    8.  
    9. Private Declare Function SendMessage Lib "user32.dll" _
    10.  Alias "SendMessageA" ( _
    11.    ByVal hwnd As Long, _
    12.    ByVal wMsg As Long, _
    13.    ByVal wParam As Long, _
    14.    ByRef lParam As Any) As Long
    15.  
    16. Private Declare Function LockWindowUpdate Lib "user32.dll" _
    17.   (ByVal hwndLock As Long) As Long
    18.  
    19. Private Const WM_USER As Long = &H400
    20. Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
    21. Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
    22. '
    23. Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
    24. '
    25. Dim MaxPos As POINT
    26. Dim CurrentPos As POINT
    27.  
    28. '----------------------------------------------------------------------
    29. Private Sub Form_Load()
    30.   Timer1.Enabled = False
    31.   Timer1.Interval = 20  'Use it to control speed
    32.   '
    33.   Dim i As Long
    34.   Dim BlnkLines As Long
    35.   RichTextBox1.Text = ""
    36.   '
    37.   ' add blank lines at top -->
    38.   BlnkLines = RichTextBox1.Height / Me.TextHeight("|")
    39.   RichTextBox1.SelStart = 0
    40.   RichTextBox1.Font = Me.Font
    41.   '
    42.   For i = 1 To BlnkLines
    43.     RichTextBox1.Text = RichTextBox1.Text & vbCrLf
    44.   Next
    45.   '
    46.   ' insert Test text -->
    47.   For i = 1 To 50
    48.     RichTextBox1.Text = RichTextBox1.Text & vbCrLf & "Line - " & i
    49.   Next
    50.  
    51. End Sub
    52.  
    53. '----------------------------------------------------------------------
    54. Private Sub Command1_Click()
    55.  
    56.   'Get maximum value for scrolling ---->
    57.   LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
    58.   RichTextBox1.SelStart = Len(RichTextBox1.Text)
    59.   Call SendMessage(RichTextBox1.hwnd, EM_GETSCROLLPOS, 0, MaxPos)
    60.   LockWindowUpdate 0
    61.   '
    62.   'Set scroll position at begining ---->
    63.   CurrentPos.X = 0
    64.   CurrentPos.Y = 0
    65.   Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    66.   '
    67.   Timer1.Enabled = True
    68.  
    69. End Sub
    70. '----------------------------------------------------------------------
    71.  
    72. Private Sub Timer1_Timer()
    73.  
    74.   If CurrentPos.Y <= MaxPos.Y Then
    75.     CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
    76.     Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    77.   Else
    78.     CurrentPos.Y = MaxPos.Y
    79.     Timer1.Enabled = False
    80.   End If
    81.  
    82. End Sub
    Last edited by iPrank; Aug 30th, 2006 at 03:04 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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?

  10. #10
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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.
    Show Appreciation. Rate Posts.

  11. #11
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Last edited by iPrank; Aug 30th, 2006 at 01:53 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  12. #12
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to make some words move up to down or down to up?

    you could do it with a picturebox:
    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Static lX As Long
    3.  
    4.     Picture1.Cls
    5.     Picture1.CurrentX = lX
    6.     Picture1.Print "Line1" & vbCrLf & "Line2" & vbCrLf & "Line3"
    7.     lX = lX - 1
    8. End Sub
    not sure how pretty it'd be though

  13. #13
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  14. #14

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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?

  15. #15
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to make some words move up to down or down to up?

    Just like textbox, RTB has a .Text property.
    VB Code:
    1. RichTextBox1.Text = "" ' clear text
    2. RichTextBox1.Text = "Blah Blah" ' some text

    Here is a RTB tutorial. I hope it will help you.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  16. #16

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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,

  17. #17
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  18. #18

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  19. #19
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to make some words move up to down or down to up?

    I've edited the code in post#6. Try it.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  20. #20

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  21. #21
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. RTB1.LoadFile "C:\aaa.rtf"
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  22. #22

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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.

  23. #23

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  24. #24
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    You first load the file and then insert blank lines.
    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  25. #25

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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?

  26. #26

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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?

  27. #27
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. ' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
    2. Option Explicit
    3.  
    4. Private Type POINT
    5.   X As Long
    6.   Y As Long
    7. End Type
    8.  
    9. Private Declare Function SendMessage Lib "user32.dll" _
    10.  Alias "SendMessageA" ( _
    11.    ByVal hwnd As Long, _
    12.    ByVal wMsg As Long, _
    13.    ByVal wParam As Long, _
    14.    ByRef lParam As Any) As Long
    15.  
    16. Private Declare Function LockWindowUpdate Lib "user32.dll" _
    17.   (ByVal hwndLock As Long) As Long
    18.  
    19. Private Const WM_USER As Long = &H400
    20. Private Const EM_GETSCROLLPOS As Long = (WM_USER + 221)
    21. Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
    22. '
    23. Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
    24. '
    25. Dim MaxPos As POINT
    26. Dim CurrentPos As POINT
    27.  
    28. '----------------------------------------------------------------------
    29. Private Sub Form_Load()
    30.   Timer1.Enabled = False
    31.   Timer1.Interval = 20  'Use it to control speed
    32.  
    33. End Sub
    34.  
    35. '----------------------------------------------------------------------
    36. Private Sub Command1_Click()
    37.   PrepareRTB
    38.   'Get maximum value for scrolling ---->
    39.   LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
    40.   RichTextBox1.SelStart = Len(RichTextBox1.Text)
    41.   Call SendMessage(RichTextBox1.hwnd, EM_GETSCROLLPOS, 0, MaxPos)
    42.   LockWindowUpdate 0
    43.   '
    44.   'Set scroll position at begining ---->
    45.   CurrentPos.X = 0
    46.   CurrentPos.Y = 0
    47.   Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    48.   '
    49.   Timer1.Enabled = True
    50.   Me.Caption = "Scrolling Started"
    51.  
    52. End Sub
    53. '----------------------------------------------------------------------
    54.  
    55. Private Sub Timer1_Timer()
    56.  
    57.   If CurrentPos.Y <= MaxPos.Y Then
    58.     CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
    59.     Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    60.   Else
    61.     CurrentPos.Y = MaxPos.Y
    62.     Timer1.Enabled = False
    63.     Me.Caption = "Scrolling Ended"
    64.   End If
    65.  
    66. End Sub
    67. '----------------------------------------------------------------------
    68. Private Sub PrepareRTB()
    69.   '
    70.   Dim i As Long
    71.   Dim BlnkLines As Long
    72.  
    73.   With RichTextBox1
    74.     .Text = ""
    75.     ' Load a file -->
    76.     .LoadFile [color=maroon]"C:\SomeFile.rtf"[/color]
    77.     '
    78.     ' add blank lines at top -->
    79.     BlnkLines = .Height / Me.TextHeight("|")
    80.     .SelStart = 0
    81.     .SelFontName = Me.Font.Name
    82.     .SelFontSize = Me.Font.Size
    83.     .SelBold = False
    84.  
    85.     For i = 1 To BlnkLines
    86.       .SelText = vbCrLf
    87.     Next
    88.     '
    89.     ' [b]If you want the text to disappear after scrolling, uncomment following block[/b]
    90. '''    ' add blank lines at bottom -->
    91. '''    .SelStart = Len(.Text)
    92. '''    .SelFontName = Me.Font.Name
    93. '''    .SelFontSize = Me.Font.Size
    94. '''    .SelBold = False
    95. '''
    96. '''    For i = 1 To BlnkLines
    97. '''      .SelText = vbCrLf
    98. '''    Next
    99.    
    100.   End With
    101. 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.
    Last edited by iPrank; Aug 31st, 2006 at 03:13 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  28. #28

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  29. #29
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How to make some words move up to down or down to up?

    May be this time it will work
    VB Code:
    1. ' [b]Add a RichTextBox, a CommandButton and a Timer in a form[/b]
    2. Option Explicit
    3.  
    4. Private Type POINT
    5.   X As Long
    6.   Y As Long
    7. End Type
    8.  
    9. Private Declare Function SendMessage Lib "user32.dll" _
    10.  Alias "SendMessageA" ( _
    11.    ByVal hwnd As Long, _
    12.    ByVal wMsg As Long, _
    13.    ByVal wParam As Long, _
    14.    ByRef lParam As Any) As Long
    15.  
    16. Private Declare Function LockWindowUpdate Lib "user32.dll" _
    17.   (ByVal hwndLock As Long) As Long
    18.  
    19. Private Const WM_USER As Long = &H400
    20. Private Const EM_SETSCROLLPOS As Long = (WM_USER + 222)
    21. '
    22. Private Const VSCROLL_SPEED As Long = 1 ' Number of pixels to scroll. Use it to control speed
    23. '
    24. Dim MaxY As Long
    25. Dim CurrentPos As POINT
    26. '----------------------------------------------------------------------
    27. Private Sub Form_Load()
    28.   Timer1.Enabled = False
    29.   Timer1.Interval = 20  'Use it to control speed
    30. End Sub
    31. '----------------------------------------------------------------------
    32. Private Sub Command1_Click()
    33.   PrepareRTB
    34.   Timer1.Enabled = True
    35.   Me.Caption = "Scrolling Started"
    36. End Sub
    37. '----------------------------------------------------------------------
    38. Private Sub Timer1_Timer()
    39.   If CurrentPos.Y <= MaxY Then
    40.     CurrentPos.Y = CurrentPos.Y + VSCROLL_SPEED
    41.     Call SendMessage(RichTextBox1.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    42.   Else
    43.     CurrentPos.Y = MaxY
    44.     Timer1.Enabled = False
    45.     Me.Caption = "Scrolling Ended"
    46.   End If
    47. End Sub
    48. '----------------------------------------------------------------------
    49. Private Sub PrepareRTB()
    50.   Dim i As Long
    51.   Dim BlnkLines As Long
    52.  
    53.   With RichTextBox1
    54.     .Text = ""
    55.     LockWindowUpdate RichTextBox1.hwnd ' to reduce flickering
    56.     .LoadFile "C:\SomeFile.rtf" ' Load a file
    57.     '----------------------------------
    58.     ' add blank lines at top -->
    59.     BlnkLines = .Height / Me.TextHeight(" ")
    60.     .SelStart = 0
    61.     .SelFontName = Me.Font.Name
    62.     .SelFontSize = Me.Font.Size
    63.     .SelBold = False
    64.  
    65.     For i = 1 To BlnkLines
    66.       .SelText = vbCrLf
    67.     Next
    68.     '----------------------------------
    69.     MaxY = (.Height / Screen.TwipsPerPixelY) - 6 ' (-6) pixel is for the border)
    70.     LockWindowUpdate 0
    71.     '----------------------------------
    72.     'Set scroll position at begining ---->
    73.     CurrentPos.X = 0
    74.     CurrentPos.Y = 0
    75.     Call SendMessage(.hwnd, EM_SETSCROLLPOS, 0, CurrentPos)
    76.   End With
    77. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  30. #30

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    47

    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

  31. #31
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width