Hi,
I'm using UltraOptionSet.
I want that its text will be on its left side instead of its right side.
How can I do this?
Thanks,Yael
Hi Yael,
There's no property for this on the control, but you can do it using a CreationFilter, and it's a pretty simple one.
public class MyUltraOptionSetCreationFilter : IUIElementCreationFilter { #region IUIElementCreationFilter Members void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { // Do nothing } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { OptionSetOptionButtonUIElement optionSetOptionButtonUIElement = parent as OptionSetOptionButtonUIElement; if (optionSetOptionButtonUIElement != null) { optionSetOptionButtonUIElement.CheckAlign = ContentAlignment.MiddleRight; } return false; } #endregion }
Hi Mike,
How can i user this with optionset?
How can I extend this class with my base Control Class?
Me.UltraOptionSet1.CreationFilter = New MyUltraOptionSetCreationFilter()
Thank u...
It Works,..
My real problem is The alignment of RadioButton in the Group.
I want to align radiobutton in the center of the UltraOptionSet. How can i do that?
My option set adds radiobutton at runtime.
You want the radio buttons in the center? Do you mean vertically or horizontally? Where would the text go?
You could use a CreationFilter to rearrange the items however you want, you just set the Rect of each element.
Yes, I want radio button with text in center horizontally.
And I don't have idea of CreationFilter. Can you show me some code for this?
It's still not clear to me exactly what you want. You want the text and the radio button both to be centered? Seems like a very strange UI to me. The radio buttons would not be lined up and you would have sort've jagged edges on both sides. That's really what you want?
Thank you so much Mike,
Cheers............
Okay, not I see why your question didn't make sense to me in the first place. Your OptionSet is only tall enough to show one item. The sample code I posted here is intended for an OptionSet where the items are displayed vertically. If you make the OptionSet in your sample taller, you will see that all of the items are centered.
To center everything like you seem to want is a lot more complex. You have to get all of the elements, figure out the total width needed, then offset each element.
public class MyUltraOptionSetCreationFilter : Infragistics.Win.IUIElementCreationFilter { #region IUIElementCreationFilter Members void Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements(Infragistics.Win.UIElement parent) { if (parent is Infragistics.Win.OptionSetEmbeddableUIElement) { int? left = null; int? right = null; foreach (Infragistics.Win.UIElement element in parent.ChildElements) { if (element is Infragistics.Win.OptionSetOptionButtonUIElement) { Rectangle rect = element.Rect; if (left == null) left = rect.Left; else left = Math.Min(left.Value, rect.Left); if (right == null) right = rect.Right; else right = Math.Max(right.Value, rect.Right); } } if (left.HasValue && right.HasValue) { int requiredWidth = right.Value - left.Value; int availableWidth = parent.RectInsideBorders.Width; int newLeft = (availableWidth - requiredWidth) / 2; int offset = newLeft - left.Value; if (offset != 0) { foreach (Infragistics.Win.UIElement element in parent.ChildElements) { element.Rect = new Rectangle( element.Rect.X + offset, element.Rect.Y, element.Rect.Width, element.Rect.Height); } } } } } bool Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements(Infragistics.Win.UIElement parent) { return false; } #endregion }
public class MyUltraOptionSetCreationFilter : Infragistics.Win.IUIElementCreationFilter { #region IUIElementCreationFilter Members void Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements(Infragistics.Win.UIElement parent) { if (parent is Infragistics.Win.OptionSetEmbeddableUIElement) { int? left = null; int? right = null; foreach (Infragistics.Win.UIElement element in parent.ChildElements) { if (element is Infragistics.Win.OptionSetOptionButtonUIElement) { Rectangle rect = element.Rect; if (left == null) left = rect.Left; else left = Math.Min(left.Value, rect.Left); if (right == null) right = rect.Right; else right = Math.Max(right.Value, rect.Right); } } if (left.HasValue && right.HasValue) { int requiredWidth = right.Value - left.Value; int availableWidth = parent.RectInsideBorders.Width; int newLeft = (availableWidth - requiredWidth) / 2; int offset = newLeft - left.Value; if (offset != 0) { foreach (Infragistics.Win.UIElement element in parent.ChildElements) { element.Rect = new Rectangle( element.Rect.X + offset, element.Rect.Y, element.Rect.Width, element.Rect.Height); } } } } } bool Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements(Infragistics.Win.UIElement parent) { //Infragistics.Win.OptionSetOptionButtonUIElement optionSetOptionButtonUIElement = parent as Infragistics.Win.OptionSetOptionButtonUIElement; //if (optionSetOptionButtonUIElement != null) //{ // //optionSetOptionButtonUIElement.Rect = new Rectangle(parent.Rect.X, parent.Rect.Y + 1, parent.Rect.Width - 2, optionSetOptionButtonUIElement.Rect.Height - 1); // optionSetOptionButtonUIElement.CheckAlign = ContentAlignment.MiddleLeft; // optionSetOptionButtonUIElement.TextHAlign = Infragistics.Win.HAlign.Center; //} return false; } #endregion }
Mike, PFA for sample code.
The code is not working for me.
Did you modify the code I posted here? I tested this in an OptionSet with 5 items and it worked fine for me with no overlap.
Maybe you could post a small sample project demonstrating the behavior you are getting.