Results 1 to 7 of 7

Thread: RichTextBox Line Highlight and Autoscroll

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    21

    RichTextBox Line Highlight and Autoscroll

    Hello All- I am trying to build a language tool, basically I am getting lines of text into a richtextbox and playing the audio for that line. Things are working great except that I want to highlight the text being played and autoscroll when it plays the next line.

    Here is what I am doing I have a button which gets a bunch of audio files from a folder then I get the same lines of text as in the audio from the database and dump them in the richtextbox, then the player plays those lines and the same lines are displayed in the richtextbox.


    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            AxWindowsMediaPlayer1.currentPlaylist.clear()
            timerDuration.Enabled = False
    
            Dim oMedia As WMPLib.IWMPMedia
    
            Dim mp3fileName As String
    
            Dim d As Integer
            For d = Fromnumber to Tonumber
    
                mp3fileName = mp3fileName + ".mp3"
    
                    oMedia = AxWindowsMediaPlayer1.newMedia(folderName & "\" & mp3fileName)
                    AxWindowsMediaPlayer1.currentPlaylist.appendItem(oMedia)
    
                    'MsgBox(folderName)
                End If
    
            Next
    
            timerDuration.Enabled = True
            AxWindowsMediaPlayer1.Ctlcontrols.play()
    
    
    
    Dim mySelectQuery As String
            mySelectQuery = "SELECT * from table where (paraID = '" & ID & "')  and lines between '" & FromNumber & "' and '" & ToNumber & "'"
            Dim sqConnection As New SQLiteConnection(connString)
            Dim sqCommand As New SQLiteCommand(mySelectQuery, sqConnection)
            sqCommand.Connection.Open()
            Dim sqReader As SQLiteDataReader = sqCommand.ExecuteReader()
    
            ExtRichTextBox1.Clear()
            ExtRichTextBox1.SelectionIndent = 15
    
            If sqReader.HasRows Then
                Do While sqReader.Read()
    
                    ExtRichTextBox1.AppendText(sqReader.GetString(1))
                    ExtRichTextBox1.AppendText(Environment.NewLine)
    
                Loop
    
            Else
                MsgBox("No rows returned.")
            End If
            sqConnection.Close()
            sqConnection.Dispose()
    
        End Sub

    Then I have a timer which keeps track so to get the duration and time etc


    Code:
    Private Sub timerDuration_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerDuration.Tick
    
            Dim remain, minutes As Integer
            Dim seconds, elapsedtime As String
    
            ''Displays length of current playing track or movie.
            lblTime.Text = AxWindowsMediaPlayer1.currentMedia.durationString()
    
            remain = AxWindowsMediaPlayer1.currentMedia.duration - AxWindowsMediaPlayer1.Ctlcontrols.currentPosition
            minutes = (remain \ 60).ToString("00")
            seconds = (remain Mod 60).ToString("00") 
           elapsedtime = minutes & ":" & seconds
    
            lblDuration.Text = elapsedtime
    
            Dim rbt As String
            rbt = AxWindowsMediaPlayer1.currentMedia.name
            rbt = rbt.Substring(3)
    
            lblrbt.Text = rbt
    
            If AxWindowsMediaPlayer1.playState = WMPPlayState.wmppsStopped Then
                lblTime.Text = "00:00"
                lblDuration.Text = "00:00"
                timerDuration.Enabled = False
                'timerDuration.Stop()
            End If
        End Sub
    Now my question is how to highlight the text the audio is playing and autoscroll the highlight to the next line when the audio starts the next line.
    Or if someone has a similar implementation that I can take notes from will be highly appreciated also.

    Thanks for your help guys.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: RichTextBox Line Highlight and Autoscroll

    Is there any purpose in putting the lines into a RichTextBox other than using its highlight abilities because this would be much easier in a listbox where you would simply have to obtain the position in the playlist of the current file (I assume that's possible?) and change the Selected Index in the list box accordingly as part of the tick event.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    21

    Re: RichTextBox Line Highlight and Autoscroll

    Thanks for the reply, I have never thought of using a listbox, so I am not sure if it will be easier or a nightmare to achieve what I am trying to do. maybe someone with more experience than me would be able to chip in, I have been hung with this problem for quite a while so would really appreciate everyones expertise here. Thanks for all your time.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    21

    Re: RichTextBox Line Highlight and Autoscroll

    Hi Guys - Is my request such a nightmare that only one person has responded to it, among all the experts out there, I really dont know where else to go, if you guys tell me to rebuild from scratch I will do it, its just that I need some direction and examples to follow. So please help me I am really stuck out here.

    Thanks for the help.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: RichTextBox Line Highlight and Autoscroll

    I suspect that were you to show a little more willingness to try the suggestions that have been made to you, more people would be willing to offer advice on implementing them. One interpretation of the absence of further ideas is, after all, that the one you have been given is workable and not in need of any further comment!

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,543

    Re: RichTextBox Line Highlight and Autoscroll

    I would use a list box... that's what I've done in the past... I forget the name of the property off hand, but there's a property that when set, when something is selected in the listbox, it will scroll into view, if it isn't. Setting that is half the work... from there, all you need to is select each item in the list (set the .SelectedIndex property) ... that will then highlight that line, which will cause it to scroll into view... It's all quite simple and easy.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2011
    Posts
    21

    Re: RichTextBox Line Highlight and Autoscroll

    I just implemented the listbox feature, seemed cool at first but then I discovered you cant word wrap a listbox, at least I havent found any easy way of doing it.
    Now my text can go on more than 10 lines, and if I select the multiline feature in the properties, its just wraps the text, and I havent found a way to seperate the lines say after a full stop, and it just makes you scroll horizontally till the cows come home.

    Appreciate your replies guys, but is there a way to wordwrap a listbox without a huge horizontal bar ?

Tags for this Thread

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