Creating clickable text, need help

Hello,

I am interested in creating “clickable text area”. let me explain what I mean by that.

Ideally, in this program, user will be able to drop a text file contain random text (letters only, no spacebars), ranging from anywhere of 2 letters to 10,000 letters. In this case, the user drops a text file containing “ABCDEFGHIJKLM”. I want the text to appear on the screen nicely spaced (a scroll bar will be needed if no space is left). Then, the user should be able to select one or more letters (in this example, the user selects C and G). Then finally, I want a message box that will say that C is the 3rd letter in the random text file that was used. Or the other letter selected is the 8th letter in the text file, and so forth. The letters can be repeatable, so for example, a person may choose another letter C down the road that is 50th letter in the text file.

I want to output all of these positions depending on what the user selects.

I am very new to xojo and if I can get any help on this, no matter how small, it will be really appreciated!

Thanks all.

You need to have a good look at all canvas examples.

Let’s pick your problem apart.

  1. You need to paint the characters. I assume that they will be in one row to make calculations easier. You need to do a loop, assign a width and then do a drawstring for each character.

  2. After the drop when you want a letter clicked: you need to read the mouse down coordinates. With this you calculate your letter. That’s why you need the width for each character and only one row. 2 rows will make things a bit more complicated.

  3. Put the character into an array. Your paint event needs to look up the array so that you know that in addition to the character it now also needs to paint the circle around the character.

To make things easy, I would suggest this:

[quote]
Add a listbox to the screen, width 390
Set the DefaultRowHeight to be 40
Set the font to be Courier New, size 40[/quote]

Fill the listbox with rows made up from 15 characters at a time
If your file has 10,000 letters, you end up with over 650 rows

When someone clicks on a row, you will get a cellclick event
This passes you a ROW, and X and a Y

charpos =    (ROW * 15) +   ( x \\25) +1

To highlight the letter, you need to add code to the celltextpaint or cellbackgroundpaint events.
I’ll leave that to you.

Thanks for the guidance Jeff! I am currently trying this out. Since listbox does not allow multilines, can you tell me how I can limit it to 15 characters at a time?

Thanks!

listbox.addrow (first 15 chars)
listbox.addrow (next 15 chars)
and so on.