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
Thanks for sharing some information about the alignment of ultraoption set here. I want to share this info with top cv people, and ask them what they think about this. It will be great.
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.