locked
Making text clickable RRS feed

  • Question

  • Hello,

     

    Can anyone assist me with more information as to how I can make words in a textblock or rich textbox linkable? I.e. that is when I click on the word it should move me to the article within the textbox.

    There will only be one control a textblock or richtext box and I would like to make the GoTo 000 clickable. Is this possible?

     

    GoTo 001: John's birthday party

    GoTo 002:A story about Peter Pan

    GoTo 003:Your friend Peter

    GoTo 004:This is it

    GoTo 005:Friendly Friday

    GoTo 006:Today is tomorrow

    GoTo 007:What about tommorow?

    GoTo 008:Then she came along

    GoTo 009:A good day to fly

    GoTo 010:Some like it vrot

    GoTo 011:Not today

    GoTo 012:Read me

    GoTo 013: Hello World

    GoTo 014: Yesterday is here

    GoTo 015:Tomorrow is gone

    GoTo 016:Jump up

    GoTo 017:Time to leave

    GoTo 018:Get up and grow

    ************************************************************************************************************************

     

    GoTo 001:

     

    John's birthday party

     

    Welcome to this invitation to Johns birthday party, where all is personally invited to attend.....

     

    ………………………………………………

    So I would like to make the GoTo 001, GoTo 002: and so forth in the textbox clickable.

    Once clicked I would like it to do the following.

     

    ScrollToSection("GoTo 0018:")

       

        Private Sub ScrollToSection(ByVal strSection As String)

            For x = 0 To (Txttest.Lines.Count - 1)

                If Txttest.Lines(x) = strSection Then

                    Txttest.SelectionStart = Txttest.GetFirstCharIndexFromLine(x)

                    Txttest.ScrollToCaret()

                End If

            Next

        End Sub

     

    Thank you for Any help!

    Tuesday, October 8, 2013 7:29 AM

Answers

  • In this code place your cursor anywhere in the RichTextBox (RTB) on the GoTo line you want to find the article text for and left click to move the caret to that location. Then right click the mouse and the rest is automatic.

    The article text subject has to match the GoTo line text. However the article paragraph(s) below the article subject line can not match the article subject line exactly or the app will find that text instead.

    Text file text, followed by code, followed by image. In the top pic of the image I placed the cursor on the "Peter Pan" GoTo line then left clicked the mouse to move the RTB caret to that line then right clicked the mouse which moved the caret to the article subject line for Peter Pan and moved the caret to the beginning of that subject line then scrolled the RTB to the caret location.

    GoTo 001:John's birthday party
    GoTo 002:A story about Peter Pan
    GoTo 003:Your friend Peter
    GoTo 004:This is it
    GoTo 005:Friendly Friday
    GoTo 006:Today is tomorrow
    GoTo 007:What about tommorow?
    GoTo 008:Then she came along
    GoTo 009:A good day to fly
    GoTo 010:Some like it vrot
    GoTo 011:Not today
    GoTo 012:Read me 
    GoTo 013:Hello World
    GoTo 014:Yesterday is here
    GoTo 015:Tomorrow is gone
    GoTo 016:Jump up
    GoTo 017:Time to leave
    GoTo 018:Get up and grow
    
    
    John's birthday party
    
    Welcome to this invitation to Johns birthday party, where all is personally invited to attend.....
    
    
    
    A story about Peter Pan
    
    Hello. This is about Peter Pan.
    
    
    


    Option Strict On
    
    Imports System.IO
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            For Each CTL As Control In Me.Controls
                If CTL.Name = "RichTextBox1" Then
                    AddHandler CTL.MouseDown, AddressOf MouseRightDown
                End If
            Next
            Dim SR As New StreamReader("C:\Users\John\Desktop\GoToTest.Txt")
            RichTextBox1.Text = SR.ReadToEnd
            SR.Close()
        End Sub
    
        Private Sub MouseRightDown(sender As Object, e As MouseEventArgs)
            If e.Button = Windows.Forms.MouseButtons.Right Then
                Try
                    Dim RichTextBox1Line As String = RichTextBox1.Lines(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart))
                    RichTextBox1Line = RichTextBox1Line.Remove(0, 9)
                    Dim indexToText As Integer = RichTextBox1.Find(RichTextBox1Line, 0, RichTextBoxFinds.Reverse)
                    RichTextBox1.SelectionLength = 0
                    RichTextBox1.ScrollToCaret()
                Catch ex As Exception
                End Try
            End If
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Tuesday, October 8, 2013 4:53 PM

All replies

  • If there's only one control then where are all of these GoTo items displayed? And where's the article they are associated to in order to test this?

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Tuesday, October 8, 2013 1:04 PM
  • Hi there,

    All the information displayed in a rich textbox/ textblock that's the only control. The Textbox has all the information as listed above so within the textbox I would like to make the GoTo 001: clickable?

    Tuesday, October 8, 2013 1:17 PM
  • You didn't answer my questions though.

    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Tuesday, October 8, 2013 1:25 PM
  • Is the information to access the articles text in the top of the RichTextBox? And where is the article? I need the article that all of those GoTo items are associated to. So below is how the GoTo should be displayed in the top of the RichTextBox?

    GoTo 001: John's birthday party
    GoTo 002:A story about Peter Pan
    GoTo 003:Your friend Peter
    GoTo 004:This is it
    GoTo 005:Friendly Friday
    GoTo 006:Today is tomorrow
    GoTo 007:What about tommorow?
    GoTo 008:Then she came along
    GoTo 009:A good day to fly
    GoTo 010:Some like it vrot
    GoTo 011:Not today
    GoTo 012:Read me 
    GoTo 013: Hello World
    GoTo 014: Yesterday is here
    GoTo 015:Tomorrow is gone
    GoTo 016:Jump up
    GoTo 017:Time to leave
    GoTo 018:Get up and grow


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Tuesday, October 8, 2013 2:20 PM
  • All the text below are already populated in the textbox.

    Lets say I click Click GoTo 001: it should take me to the bottom of the textbox to the article John's birthday party. What I would like to know is how to make GoTo 001: a hyperlink so that I can scroll to bottom of text to John's birthday party if one can do that.

    GoTo 001: John's birthday party

    GoTo 002: A story about Peter Pan

    GoTo 003: Your friend Peter

    GoTo 004: This is it

    GoTo 005: Friendly Friday

    GoTo 006: Today is tomorrow

    GoTo 007: What about tommorow?

    GoTo 008: Then she came along

    GoTo 009: A good day to fly

    GoTo 010: Some like it vrot

    GoTo 011: Not today

    GoTo 012: Read me

    GoTo 013: Hello World

    GoTo 014: Yesterday is here

    GoTo 015: Tomorrow is gone

    GoTo 016: Jump up

    GoTo 017: Time to leave

    GoTo 018: Get up and grow


    ************************************************************************************************************************

     

    GoTo 001:

     

    John's birthday party

     

    Welcome to this invitation to Johns birthday party, where all is personally invited to attend.....

    Tuesday, October 8, 2013 2:21 PM
  • In this code place your cursor anywhere in the RichTextBox (RTB) on the GoTo line you want to find the article text for and left click to move the caret to that location. Then right click the mouse and the rest is automatic.

    The article text subject has to match the GoTo line text. However the article paragraph(s) below the article subject line can not match the article subject line exactly or the app will find that text instead.

    Text file text, followed by code, followed by image. In the top pic of the image I placed the cursor on the "Peter Pan" GoTo line then left clicked the mouse to move the RTB caret to that line then right clicked the mouse which moved the caret to the article subject line for Peter Pan and moved the caret to the beginning of that subject line then scrolled the RTB to the caret location.

    GoTo 001:John's birthday party
    GoTo 002:A story about Peter Pan
    GoTo 003:Your friend Peter
    GoTo 004:This is it
    GoTo 005:Friendly Friday
    GoTo 006:Today is tomorrow
    GoTo 007:What about tommorow?
    GoTo 008:Then she came along
    GoTo 009:A good day to fly
    GoTo 010:Some like it vrot
    GoTo 011:Not today
    GoTo 012:Read me 
    GoTo 013:Hello World
    GoTo 014:Yesterday is here
    GoTo 015:Tomorrow is gone
    GoTo 016:Jump up
    GoTo 017:Time to leave
    GoTo 018:Get up and grow
    
    
    John's birthday party
    
    Welcome to this invitation to Johns birthday party, where all is personally invited to attend.....
    
    
    
    A story about Peter Pan
    
    Hello. This is about Peter Pan.
    
    
    


    Option Strict On
    
    Imports System.IO
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            For Each CTL As Control In Me.Controls
                If CTL.Name = "RichTextBox1" Then
                    AddHandler CTL.MouseDown, AddressOf MouseRightDown
                End If
            Next
            Dim SR As New StreamReader("C:\Users\John\Desktop\GoToTest.Txt")
            RichTextBox1.Text = SR.ReadToEnd
            SR.Close()
        End Sub
    
        Private Sub MouseRightDown(sender As Object, e As MouseEventArgs)
            If e.Button = Windows.Forms.MouseButtons.Right Then
                Try
                    Dim RichTextBox1Line As String = RichTextBox1.Lines(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart))
                    RichTextBox1Line = RichTextBox1Line.Remove(0, 9)
                    Dim indexToText As Integer = RichTextBox1.Find(RichTextBox1Line, 0, RichTextBoxFinds.Reverse)
                    RichTextBox1.SelectionLength = 0
                    RichTextBox1.ScrollToCaret()
                Catch ex As Exception
                End Try
            End If
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Tuesday, October 8, 2013 4:53 PM
  • Hi Mr Monkey,

    Thank you so much for assisting me with this I really really do appreciate all the effort that you have done!!!!!!! 

    I was wondering maybe if it was possible to declare the text in the RTB to a string and then searching the string for "Story 001:" to "Story 018:" or use and array if text = "Story 001:" then make it blue and underlined so that when someone click on it, it will invoke ScrollToSection("Story 001")  and the RTB will scroll to this Story. Is this possible?

    I understand what you have done on top but left clicking and then right clicking is a bit more complicated than having a link which one can just click once.

    I have added more text below which the text document will contain and changed the GoTo to Story as this will be stagnate. Thank you for all your help so far.

    Text document will contain the following.

    _____________________________________

    Story 001: John's birthday party

    Story 002: A story about Peter Pan

    Story 003: Your friend Peter

    Story 004: This is it

    Story 005: Friendly Friday

    Story 006: Today is tomorrow

    Story 007: What about tommorow?

    Story 008: Then she came along

    Story 009: A good day to fly

    Story 010: Some like it vrot

    Story 011: Not today

    Story 012: Read me

    Story 013: Hello World

    Story 014: Yesterday is here

    Story 015: Tomorrow is gone

    Story 016: Jump up

    Story 017: Time to leave

    Story 018: Get up and grow


    ************************************************************************************************************************

     

    Story 001

     

    John's birthday party

     

    Welcome to this invitation to Johns birthday party, where all is personally invited to attend.....




    ************************************************************************************************************************

    Story 002: 

    A story about Peter Pan


    We all like to talk about how the star system as we know it is dead and that there are no real movie stars left.  But what we fail to realize is that, especially when it comes to mega-budget studio releases, genuine movie stars are an essential ingredient. Sandra Bullock may be on the verge of being crowned one of the biggest movie stars on Earth, but I’ll get to that on another day.



    ************************************************************************************************************************


    Story 003: 

    Your friend Peter


    But what matters is that Bullock and George Clooney are the kind of recognizable and trusted celebrities that can promote a film like Gravity in the kinds of media outlets (tabloids, fashion magazines, talk shows, etc.) that serve the audience demographics that might not otherwise know about or care about a thriller set in space. These days, it’s all about concept + movie stars. The concept is king, but you need star power, real star power, to justify the budget.

    It’s the difference between, for example, the $195 million Jack the Giant Slayer ($197m worldwide) and the $215m Oz: The Great and Powerful ($493m worldwide). Among other reasons for the respective financial results is that one had character actors like Stanley Tucci and low-level stars like Ewan McGregor surrounding the mostly unknown Nicholas Holt while the latter had media-friendly stars like James Franco, Rachel Weisz, and Mila Kunis to do the talk show rounds and highlight magazine covers the week prior to release.

    Now a small independent drama with those three names isn’t going to do blockbuster business, even one directed by Gravity helmer Alfonso Cuaron after today.  But those names will intrigue and entice those on the fence about taking their kids to a mega-budget Oz prequel. That’s the real value of movie stars, and that’s the real value of having names like Sandra Bullock and George Clooney selling your intense, claustrophobic space adventure.






    ************************************************************************************************************************

    Story 004: 

    This is it


    This should be a simple idea, but here we go: If you don’t give away all of the best parts of the movie in your marketing campaign, you’ll have people talking about all of the wonderful moments or imagery they weren’t expecting to see.  Whether it’s Universal hiding the T-Rex in the Jurassic Park campaign, 20th Century Fox hiding the appearance of a light saber-wielding Yoda in Attack of the Clones, or Paramount omitting a post-credit cameo of Samuel L. Jackson in Iron Man from press screenings,  narrative and visual surprises give way to word-of-mouth and buzz.

    Giving away the movie may get them into the theater on opening weekend, but it removes the shared experience of discovery that creates real buzz among moviegoers. Warner Bros.’ successful Gravity campaign was a successful attempt at selling the core story (Bullock and Clooney are two astronauts who get into trouble while in space) without giving away the major narrative beats or really much of anything that happens after the first act.

    As such, there are a number of buzz-worthy images that audiences got to discover for the first time while actually seeing the movie. It’s that kind of “you have to see it for yourself” buzz that creates real word-of-mouth excitement and repeat viewership beyond just opening weekend.



    ************************************************************************************************************************

    Story 005: 


    Friendly Friday

    We can debate all we want about which films are critic-proof and which major films will or won’t benefit from positive critical reviews.  But Warner Bros. knew what they had and let the press see it early enough to build a mountain of positive reviews, but not so early so that the inevitable backlash could begin before opening weekend.

    As of now, the film sits with 5 negative reviews out of 218 on Rotten Tomatoes, for a 98% fresh ranking and (more importantly) an average score of 9.1 out of 10. For general audiences who don’t see every genre release week in and week out, those kind of reviews were exactly what was needed to get them into the theater this weekend. The reviews, such as mine, not only emphasized the film’s sheer quality, but also the absolute necessity of seeing it in theaters and yes, in 3D and IMAX if possible.

    A chorus of critics telling audiences that not only was Gravity a masterpiece but absolutely demanded a big-screen viewing experience was essential in not just getting general moviegoers out of their house but also in encouraging them to pay that 3D and/or IMAX up-charge, which led to a stunning ticket count of 80% 3D and 21% IMAX for the film’s $55.8 million debut weekend. In this case, critics darn-well mattered.

    I was happy to be among the joyful chorus, both encouraging viewership of a terrific movie and rebutting the cliche that movie critics hate anything that is mainstream or popular. Wrong on both counts.





    ************************************************************************************************************************

    Story 006: 

    Today is tomorrow

    As a general rule, opening weekend is about marketing while every weekend after that is about quality. But every once in awhile, a film is so good, better than expected, that the buzz starts early enough among the ticketbuyers to actually boost the film’s opening weekend.  The film’s $17.5 million Friday could easily have led to a normal 2.75x weekend multiplier and a solid, but not-record breaking $48m.

    Instead, the word-of-mouth spread like wildfire, through old-school chit-chat and various social networks, which caused the film’s Saturday number to shoot 31% up from its Friday number, giving the film a stunning 3.18x weekend multiplier. The film earned $15 million on Sunday, or just 14% less than it did on Friday. These are frankly the kind of Saturday jumps and Sunday drops that we just don’t see outside of animated features released outside of summer.

    For a live-action film to do these kind of figures is a sure sign that word has already spread.  The audience demo was actually 59% ages 35 or older, which is quite rare for an opening of this size. But word-of-mouth will guarantee that not only will younger audiences check it out in the coming weeks but older audiences who don’t necessarily rush out to see the newest films will also make a point to see what all of the fuss is about.

    In conclusion, what we have here is a perfect storm where everything went right for all involved.  The film had terrific reviews while actually living up to the hype. Warner Bros. marketing got people into the theater without giving away the whole movie, which in turn allowed buzz to spread like wildfire.  Sandra Bullock and George Clooney helped rope in those who get their movie news from Ellen while the free press over the film’s debut weekend, it’s inevitable Oscar buzz, and the requirement that it be seen in IMAX 3D will only fuel more interest in the coming weeks.

    This is how popular film making and successful marketing is supposed to work when everything goes right.  And kudos to all involved for making it happen. Have you seen Gravity yet? If so, in what format did you view it in and how was your viewing experience? Please share below.



    ************************************************************************************************************************

    Story 007: 

    What about tommorow?


    Spencer Rascoff is only 37. Yet, the Harvard grad and father of three has already accomplished so much.

    He co-founded Hotwire.com and served as a VP for Expedia EXPE -3.13%; he held the roles of CFO, vice president of marketing and COO at Zillow; and in 2008, Rascoff was promoted to chief executive of the popular real estate information site.


    ************************************************************************************************************************

    Story 008: 

    Then she came along


    Wondering how the Zillow CEO has achieved and maintained his success? His weekend routine has something to do with it.

    “My weekends are an important time to unplug from the day-to-day and get a chance to think more deeply about my company and my industry,” Rascoff says. “Even when I’m technically not working, I’m always processing in the background and thinking about the company. Weekends are a great chance to reflect and be more introspective about bigger issues.”

    He says he always spends weekends with his family. “Even if I’m on the road on a Friday and have to be back in that same city the following week, I always come home no matter what.”


    ************************************************************************************************************************


    Story 009: 

    A good day to fly


    Last year Rascoff’s New Year’s resolution was to refrain from checking e-mail during the day on Saturdays–but it didn’t stick. “I’m trying again this year and am having more luck,” he says. “I have three young children so weekends are usually an exhausting but fun smorgasbord of fort-building, bike-riding, soccer-playing, chess-tournament-competing, stroller-pushing, zoo-going, diaper-changing, book-reading and birthday-party-going. I never go into the office on weekends but I do check e-mail at night, and I use weekends as an opportunity to catch up on work-related reading.”

    Laura Vanderkam, author of What the Most 


    ************************************************************************************************************************



    Story 010: 

    Some like it vrot

    Consider this a reiteration of what should be some pretty obvious points about Gravity‘s stunning and record-breaking $55.8 million debut weekend, but sometimes we need to be reminded about why the stuff that works happens to work.  To wit…


    ************************************************************************************************************************



    and so forth... until Story 18




















    Tuesday, October 8, 2013 6:27 PM
  • Why not use an HTML document and a WebBrowser control?  You could just write anchor and bookmark tags into the document.  I mean, it sounds like this is a read-only text box anyway so HTML seems like the way to go.

    If the user is going to edit the document then you have a whole other set of problems to deal with.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Proposed as answer by Frank L. Smith Tuesday, October 8, 2013 7:54 PM
    Tuesday, October 8, 2013 7:45 PM
  • I have solved my own problem by using the find statement to change "Story 001" to "Story 018" to hyper links and then invoking the ScrollToCaret function which works beautifully.

    This will be read only no editing, so HTML document and a webBrowser control would not have been what I was looking for.

    Thank you Monkey for assisting, really appreciate it!

    Tuesday, October 8, 2013 8:48 PM
  • I have solved my own problem by using the find statement to change "Story 001" to "Story 018" to hyper links and then invoking the ScrollToCaret function which works beautifully.

    This will be read only no editing, so HTML document and a webBrowser control would not have been what I was looking for.

    Thank you Monkey for assisting, really appreciate it!

    If it was read-only, no editing, then a WebBrowser and HTML document would work perfectly (and far more efficiently).  But so long as your documents are fairly short and there is no possibility of an article containing a heading as part of the text, then what you are doing will probably be ok.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, October 9, 2013 2:37 PM