1

I am developing a C# application to communicate with a MUD/MOO server. Basically it takes text and displays it on the screen. At the moment i'm using a RichTextBox to display the text and I have coloured text working fine and I only have to implement URLs, however while doing this I discovered that to add URLs with custom text (e.g. NOT http://, like: Click here) I need to use a Win32 API, I can't do this... at all. This needs to work in mono on linux (and possibly mac). Is there anyway to make this work? or what alternative avenues should i pursue? (I was considering switching to HTML, but is there a good cross-platform HTML control?) (All of this HAS to be free).

Thanks in advanced.

I managed to do it in the end using:

Stack<Link> Links = new Stack<Link>();
internal class Link
{
        public int starts = 0;
        public int ends = 0;
        public string url = "";
}
private string GetLink(RichTextBox rtb, Point point)
        {
            int index = rtb.GetCharIndexFromPosition(point);
            foreach (Link link in Links.ToArray())
                if (link.starts <= index && link.ends >= index)
                    return link.url;
            return "";
        }

just append all links to the Links stack, and use GetLink inside the MouseDown event :)

R4000
  • 113
  • 2
  • 7

1 Answers1

1

as an alternative you can use GtkTextView, it should be cross platform. You can add a hyper link styled text using code below:

TextTag tag  = new TextTag("link");
tag.Foreground = "blue";
tag.Underline = Pango.Underline.Single;         
textview1.Buffer.TagTable.Add(tag);

Gtk.TextIter iter = textview1.Buffer.GetIterAtOffset(0);        
textview1.Buffer.InsertWithTagsByName(ref iter, "link text", "link");

where textview1 is Gtk.TextView.

you should be able to change the cursor and react on mouse clicks using "motion-notify-event" and "event-after" events.

hope this helps, regards

serge_gubenko
  • 20,186
  • 2
  • 61
  • 64