Shorten link but still clickable in richtextbox

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 1481 Views - Last Post: 10 February 2013 - 05:51 PM Rate Topic: -----

#16 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 07 February 2013 - 05:18 PM

View Postandrewsw, on 07 February 2013 - 05:12 PM, said:

Maybe the link labels are positioned statically in the RTB(?). This would be annoying and I don't think this should be the case. They have an Anchor property so perhaps they can (somehow) be anchored at their initial position within the textbox; that is, anchored to the previous character.


Erm.. seems we can borrow code to InsertHyperlink into an RTB. This looks like it will be a lot easier, the hard work having been done already. This is what happens when other people do your Googling for you :unsure:/>


But i have been doing googling to haha and i have seen that page, i tryed a few bits then realized its for vb6 some of it, i still dont understand how i can use that insert hyperlink to be put into each of the instances of the labels? :/ sorry i dont mean to put you out , i am trying my best its just a bit complex for me at time i learn , but slowly :)
Was This Post Helpful? 0
  • +
  • -

#17 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 07 February 2013 - 05:26 PM

I haven't done this before either and, yes, it is getting a little tricky. Should be possible though :)
Was This Post Helpful? 0
  • +
  • -

#18 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 07 February 2013 - 06:03 PM

View Postandrewsw, on 07 February 2013 - 05:26 PM, said:

I haven't done this before either and, yes, it is getting a little tricky. Should be possible though :)/>



Yes it is its doing my head in , ive tried anchoring the linklabels , docking them but they are stil not moving and there is the text behind them of the same things that are moving with the scroll bar to haha

Any ideas would be much appreciated , you have already helped me so much already :)
Was This Post Helpful? 0
  • +
  • -

#19 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 05:24 AM

Can anyone shed some light on this problem please ? I'm all out of options :/
Was This Post Helpful? 0
  • +
  • -

#20 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 11:44 AM

View Postsuperfurry, on 08 February 2013 - 05:24 AM, said:

Can anyone shed some light on this problem please ? I'm all out of options

Well as the LinkLabels are proving overly complicated you could take a different approach, somewhat similar to my original array idea. The reason I believe we can change the approach is that each hyperlink-text will be on a separate line of the RTB; is this correct?

The RTB (RichTextBox) has a Lines collection. So, as you create each line, just put the display-text in the RTB and store in an array the href address that corresponds to that line. Change the text-colour to blue and underline it if you like. You can probably change the cursor for these lines to a hand but, initially, I would just do this for the whole RTB.

Then you need to use the Click event of the RTB, determine which specific line was clicked, and retrieve, and follow, the corresponding hyperlink (from the array).

If some lines are not hyperlinks, then still store something in the array (as a placeholder for that line), perhaps an empty string or "No Link". However, this would mean that the hyperlinks would also be stored as strings - but you would probably do this anyway.

If the user is able to edit the RTB content then, of course, it will likely ruin the line/hyperlink correspondence that you have created. I'm guessing that you don't want the RTB to be editable, otherwise it will difficult to maintain this correspondence.

Apart from the prior paragraph's issue the remaining fiddly bit is to determine which line was clicked on. I just found the following C# code:

private void richTextBox1_MouseClick(object sender, MouseEventArgs e)
        {
            //the number of the selected line
            int i=(e.Location.Y)/16;    // 16 is the height of each line
            // get the value of the number line.
            MessageBox.Show(this.richTextBox1.Lines[i].ToString());
           
        }

It seems a little messy to have to divide the Location by the line-height; perhaps a little more digging will reveal a more direct method to determine which line was clicked.
Was This Post Helpful? 0
  • +
  • -

#21 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 11:56 AM

Here you go:

    Private Sub RichTextBox1_Click(sender As Object, e As EventArgs) Handles RichTextBox1.Click
        Dim clickedLine As Integer = 0
        clickedLine = sender.GetLineFromCharIndex(sender.Selectionstart)
        MessageBox.Show(String.Format("You clicked line {0:d}", clickedLine))

    End Sub

Job done!!! :balloon:
Was This Post Helpful? 0
  • +
  • -

#22 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 03:22 PM

Hehe thanks mate the clicked thing is a real help , but as for getting them all in a array I'm stumped again :/ I haven't done alot of work with arrays I know how to make them but not sure how to scrape the links and text into arrays :/ ?
Was This Post Helpful? 0
  • +
  • -

#23 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 03:30 PM

You could start with the docs and there are probably tutorials available here at DIC.

You don't need to store the text in the array, just the link-addresses. Determining the line-number of the text that the user has just clicked will allow you to identify, and follow, the corresponding link-address in the array.

This post has been edited by andrewsw: 08 February 2013 - 03:31 PM

Was This Post Helpful? 0
  • +
  • -

#24 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 03:42 PM

View Postsuperfurry, on 08 February 2013 - 03:22 PM, said:

Hehe thanks mate the clicked thing is a real help , but as for getting them all in a array I'm stumped again :/ I haven't done alot of work with arrays I know how to make them but not sure how to scrape the links and text into arrays ://> ?

Erm.. I really think you should take the time to cover the fundamentals of VB.NET before attempting to work with fiddly objects such as LinkLabels (it's not surprising that you struggled with this).
Was This Post Helpful? 0
  • +
  • -

#25 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 08 February 2013 - 05:01 PM

View Postandrewsw, on 08 February 2013 - 03:42 PM, said:

View Postsuperfurry, on 08 February 2013 - 03:22 PM, said:

Hehe thanks mate the clicked thing is a real help , but as for getting them all in a array I'm stumped again ://> I haven't done alot of work with arrays I know how to make them but not sure how to scrape the links and text into arrays ://>/> ?

Erm.. I really think you should take the time to cover the fundamentals of VB.NET before attempting to work with fiddly objects such as LinkLabels (it's not surprising that you struggled with this).

Yes I know what you mean , as I said I do know how to make arrays , but the scraping links stuff is all new to me and trying to learn as I go along , ok il have ago at all this and il get back to you tomorrow :) thanks for your help
Was This Post Helpful? 0
  • +
  • -

#26 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 09 February 2013 - 04:37 PM

Still having problems seems to not be storing what want in the array :/ I give up
Was This Post Helpful? 0
  • +
  • -

#27 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 09 February 2013 - 05:17 PM

View Postsuperfurry, on 09 February 2013 - 04:37 PM, said:

Still having problems seems to not be storing what want in the array :/ I give up

Softie! Or, if you prefer, super-furry :)

If you don't already know how, take the time to learn how to debug and step-through your code. In particular, step-through the code and point your mouse at the array to see how it accumulates (or doesn't) its values (or view the Locals Window).
Was This Post Helpful? 0
  • +
  • -

#28 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 10 February 2013 - 08:19 AM

View Postandrewsw, on 09 February 2013 - 05:17 PM, said:

View Postsuperfurry, on 09 February 2013 - 04:37 PM, said:

Still having problems seems to not be storing what want in the array ://> I give up

Softie! Or, if you prefer, super-furry :)/>

If you don't already know how, take the time to learn how to debug and step-through your code. In particular, step-through the code and point your mouse at the array to see how it accumulates (or doesn't) its values (or view the Locals Window).

I won't really give up I just did for that night it was 3 am haha il keep trying , yeah I kinda know about debugging but I think I need to learn more about for each :)
Was This Post Helpful? 0
  • +
  • -

#29 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3224
  • View blog
  • Posts: 10,832
  • Joined: 12-December 12

Re: Shorten link but still clickable in richtextbox

Posted 10 February 2013 - 02:59 PM

Quote

I kinda know about debugging


There is now a great tutorial about debugging - see my signature :)
Was This Post Helpful? 0
  • +
  • -

#30 superfurry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 07-February 13

Re: Shorten link but still clickable in richtextbox

Posted 10 February 2013 - 05:51 PM

View Postandrewsw, on 10 February 2013 - 02:59 PM, said:

Quote

I kinda know about debugging


There is now a great tutorial about debugging - see my signature :)/>

Ok il have a look thanks :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2