I am trying to style a ButtonUIElement like this:
ButtonUIElement elementToAdd = new ButtonUIElement(parent);
elementToAdd.BorderStyle = UIElementBorderStyle.Raised;
but I get a "specificed method is not supported".
I also created a new Appearance object and styled the border and made the button's appearance use this object but I see no effects.
When I create a new ButtonUIElement, it's a flat grey rectangle. How can I make it look like a real button?
I assume you are adding this element into a control using a CreationFilter. In order to style the button element, what you would have to do is derive your own class from ButtonUIElement and override the InitAppearance method.
Alternately, you could use a DrawFilter and set the properties on the AppearanceData for your element there.
Thanks. My button is using the class below and I still see no borders.
internal class MyButtonUIElement : ButtonUIElement { public MyButtonUIElement(UIElement parent) : base(parent) { } protected override void InitAppearance(ref AppearanceData appearance, ref AppearancePropFlags requestedProps) { base.InitAppearance(ref appearance, ref requestedProps); appearance.BorderColor = Color.Red; appearance.BackColor2 = Color.DarkSeaGreen; } }
Here it is in C#.
class MyButtonUIElement : ButtonUIElement
{
}
get{ return buttonStyle; }}
public EMISButtonUIElement(UIElement parent): base (parent)
Hi, rdeslonde.
I have read your post. And I have applied your code in my program. but your code doesn't not work.
Why doesn't your code work in my program? Is there any code that I write any more?
public class CButtomUIElementEx : Infragistics.Win.ButtonUIElement
{ private UIElementButtonStyle buttonStyle = UIElementButtonStyle.OfficeXPToolbarButton;
public UIElementButtonStyle StyleOfButton { get { return buttonStyle; } set { buttonStyle = value; } }
public override UIElementButtonStyle ButtonStyle {
get { return buttonStyle; } }
public CButtomUIElementEx(UIElement parent) : base(parent) { }
My guess is that your button is being drawing using OS Themes. You have to set UseOsThemes on the control to False to turn off themes.
QUOTING: "My guess is that your button is being drawing using OS Themes. You have to set UseOsThemes on the control to False to turn off themes."
How do you set UseOsThemes to FALSE for a class derived from ButtonUIElement? I cannot figure this out.
Hi,
There are a number of ways to do this. If you never want the button to draw themed, then the simplest thing to do is override the DrawTheme method and return false.
Perfect! Thanks for the super-fast reply!