Hi,
when a checkbox is focused the text get a dotted rectangle around it. In our application there is no text since we use lables to the right. Is it posible to paint the dotted line around the checkbox itself?
regards
Stefan
For the next one looking for the complete solution, here it is
public partial class MyCheckEditor : UltraCheckEditor { private const int PenWidth = 1; public MyCheckEditor() { InitializeComponent(); if (!DesignMode) { CreationFilter = new FocusCreationFilter(); DrawFilter = new FocusDrawFilter(); } } private class FocusDrawFilter : IUIElementDrawFilter { private bool _wasMyCheckEditorMoved; DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { if (drawParams.Element is UltraCheckControlUIElement) { return DrawPhase.BeforeDrawElement; } if (drawParams.Element is CheckIndicatorUIElement) { return DrawPhase.BeforeDrawElement; } return DrawPhase.None; } bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { if (drawParams.Element is UltraCheckControlUIElement) { // move the UltraCheckEditor to the left for the same number of pixels // as the width of the pen because we moved every child element // to leave enough space to draw the left side of the focus rectangle if(!_wasMyCheckEditorMoved) { Control control = drawParams.ControlElement.Control; control.Size = new Size(control.Width + PenWidth, control.Height); control.Location = new Point(control.Location.X - PenWidth, control.Location.Y); _wasMyCheckEditorMoved = true; } } else if (drawParams.Element is CheckIndicatorUIElement) { if (drawParams.ControlElement.Control.Focused && (drawParams.ControlElement.Control.Text == null || drawParams.ControlElement.Control.Text.Trim() == string.Empty)) { Rectangle elementRect = drawParams.Element.Rect; Pen pen = new Pen(Color.Black, PenWidth); pen.DashStyle = DashStyle.Dot; //draw the focus rectangle outside the checkbox drawParams.Graphics.DrawRectangle(pen, elementRect.X - PenWidth, elementRect.Y - PenWidth, elementRect.Width + PenWidth, elementRect.Height + PenWidth); return false; } } return false; } } private class FocusCreationFilter : IUIElementCreationFilter { #region Implementation of IUIElementCreationFilter bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; } void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if (parent is CheckEditorCheckBoxUIElement) { // move every child element to the right for the same number of pixels // as the width of the pen to leave enough space to draw the left side of // the focus rectangle foreach (var element in parent.ChildElements) { element.Rect = new Rectangle(element.Rect.X + PenWidth, element.Rect.Y, element.Rect.Width, element.Rect.Height); } } } #endregion } }
Thanks. I think I figured this out
Please I have the same issue as you.
Please how did you implement the DrawFilter?
OysterInnovations
You won't be able to move the actual rectangle of the element without using a CreationFilter, I don't believe, since at this point the main UIElement has positioned its child element.
-Matt
I have implemented a drawfilter to draw a dotted line around the checkIndicatorUIElement. This works fine ;-) BUT since the Element is also drawn completely to the left ( x = 0 ) I want to move it a couple to pixels to the right. Somehow the location property is not the right way....
Maybe you could give me a hint what to do:
{
drawParams.Graphics.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Red), elementRect.X , elementRect.Y + 1, elementRect.Width, elementRect.Height);
}
else
return Infragistics.Win.DrawPhase.BeforeDrawElement;
#endregion