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
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.
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.
Wow, this is perfect, thank you very much, Mike!