Results 1 to 4 of 4

Thread: Color Text control?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    2

    Color Text control?

    Hello,

    I've been looking high and low for resources on getting color into a textbox of some sort.

    I'm writing an IRC application for my WM5 phone, but one of the features I really want is color support.

    Now, I've coded irc clients before, and my main one used the Richtext control in VB6 to do all my color and such; however, there doesn't seem to be a similar control for PPC.

    I've tried an irc client written by someone else (no source code available; unsure of what language) and it has color support, so I'm sure it can be done somehow.

    I tried using a Panel control and adding labels to it (which would mean one color per line of text), but even then I ran into problems - for instance, I can't get the Panel control to scroll down and reveal what was just entered.

    Any help would be greatly appreciated!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Color Text control?

    For some reason, the options for color built into the CF are drastically limitted. You might try subclassing a textbox, but it may not really do what you want, and you seem to be headed towards a slightly different solution, so let me suggest how the panel solution could be made to work. After all, you can do lots of things with panels and labels.

    I had the problem that the CF lacks the multi-select option for a listbox. My solution was to add a large panel, with a series of small panels on top of it, along with a vertical scroll bar over to the side. The small panels each had a label on it. Behind the scenes there was a class that held all of the data, and did some odd things that made the whole thing better than a normal listbox, but are irrelevant here. The key was that I filled the labels on the small panels beginning with index X where X was the value of the scrollbar.

    While this could take a fair amount of work to set up, the actual implementation really isn't that tough. The steps would be something like this:

    1) Keep the text to be displayed in an array.
    2) Whenever the scrollbar changed (or any other significant event), fill the labels from the array based on the value of the scroll bar.

    If the scroll bar is moved down, the text will appear to move up, because all of the labels will change. An additional feature you might add is to check to see whether or not the size of the array is greater than the number of labels you have, and only show the scrollbar if you need to.

    One issue you will have in this case will be that the array will have to be filled carefully. Almost certainly, you will want to split a string into chunks small enough to show on a single label (no word wrapping in this scenario), but only split at spaces or hyphens. This will take some thought, and would be a good reason to wrap the array in a class, such that the class can take a string and divide it up as needed, and spit out chunks as needed.

    By the way, this is largely how Listboxes work behind the scenes.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    2

    Re: Color Text control?

    Thank you very much for your reply!

    It seems I had almost gotten it right, but your extra steps helped me

    I'm thinking of using a monospace font, if I can find one, and draw a label for each colored item (for example, if somebody spoke a line that started off white, but had color codes to change the color to blue, it would create two labels - the white, and the yellow one.)

    How much memory does a label use? My other method I was going to try was to have a matrix of labels - one for each position a character could be - and just change each label to have the appropriate character and characteristics as text appeared on the screen - sort of like a Dos 80x25 text screen.

    I'll experiment with the information you've given me, thanks!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Color Text control?

    Just thinking about it, you might try something really funny:

    Suppose you had a series of labels, with the text moving up the screen (label1.text = label2.text, label2.text = new text, etc.) as each new message is received. If you were to set the color and alpha levels (the A of ARGB) for each of the labels the right way, the text would appear to fade away as it moved up the screen.

    I wouldn't worry about the memory usage of a label. While I don't know what it is, it is almost certainly trivial.
    My usual boring signature: Nothing

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