I need to create a fancy caption for a radio button, using multiple fonts (text and WinDings) and colors. What's the best way to do that? Rich text or HTML would be ideal, of course, but there does not seem to be any support for that in the UltraCheckEdito.
It seems that DrawFilter provides the functionality for drawing, but how can I tell the control how large the text is, i.e. how can I control the result of autosizing and the size of the focus rectangle?
TIA!Hans
Hi Hans,
There's no easy built-in way to do this.
What I would do is create UserControl with an UltraCheckedEditor and an UltraFormattedLinkLabel control. The UltraFormattedLinkLabel supports the kind of rich text you need.
Hi Mike
Thank you for your reply.
With your proposed solution I'm concerned that getting focus, mouse and keyboard handling right could turn out to be pretty hard.
Is there an alternative way that does not involve simulating user interaction behavior?
Best,Hans
I can see how that would be a concern. But since it's only two controls inside the UserControl, and only one of them has to have an UI interaction, I don't think it would be that bad.
The only alternative solution I can think of would be to use a CreationFilter to replace the TextUIElement in the UltraCheckeditor (or UltraOptionSet) with a FormattedTextUIElement. This will require a little more work and is a little trickier. It would probably solve the problem of the keyboard behavior of focus, too. But the down side is that I don't see any way to handle auto-sizing the control, which is something you mentioned in your first post as important.
So I think the first approach with the UserControl would be better. But I could be wrong.
Actually, I just thought of a third option. What if you just create an image that has the text you want and then apply it to the Appearance of your UltraCheckEditor or UltraOptionSet item?
The only down side I can see to this approach is if you are using mnemonics in your text. Since there is no actual text, they won't respond. But you could probably handle that using the form's KeyPreview functionality.
Hi Mike,
Those are interesting ideas!
It seems to be a tough call, and apparently it really depends on the exact requirements, so I went back and checked those:
We don't need the focus rectangle, and we don't really need AutoSize, because that is easy to simulate: we can override OnTextChanged() and resize the control accordingly. We don't need mnemonics either.
However, what we do need is the hover effect on the radiobutton icon (the typical circle with the dot in it) when hovering over the icon or the caption.
I think this makes the CreationFilter strategy to replace the TextUIElement in the UltraCheckeditor with a FormattedTextUIElement the first choice, right? Any helpful hints?
(Creating an image would not work well because of the following: the application supports on-the-fly switching among some 25 languages, including the CJK ones, and the texts are string resources. Maintaining images would be too much work. OTOH, we might be able to draw the image on the fly in memory -- do you think this would be easier?)
Hans
I think the image approach might be a little easier. All you have to do is put an UltraFormattedLinkLabel on your form. To generate and image, you set the Value on it and then call the Draw method and draw that control into a Bitmap. There might be a few little caveats like you might have tin invalidate or dirty the child elements before calling Draw. And the control probably needs to be Visible, so maybe you will have to position it off-screen. But this should be pretty straightforward.
The other approach would not be too tough either. You just use the CreationFilter to watch the parent of the TextUIElement. Then you remove that element and replace it with a FormattedTextUIElement. It's a little tricky to set that up and apply the value to it, though.
Are you planning to use UltraCheckEditor for this, or UltraOptionSet?
Thank you for your reply. I'll definitely use UltraCheckEditors.
The CreationFilter approach would be more satisfying conceptually, so I think I'll try this first.
Wow, this is perfect, thank you very much, Mike!
This approach is actually pretty simple when you know how to do it. The only really tricky part is applying the value to the FormattedTextUIElement. You have to use a ParsedFormattedTextValue.
I whipped up a quick sample project to show you how it's done, and it turned out to be very quick and easy.
This sample isn't very efficient. So if you are using dozens of these checkboxes, it might be wise to cache the ParsedFormattedTextValue and only create new ones when the text changes. But if you are only using a few, and the text is relatively short and not too complex, it should be okay just as I have it.