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
HOWTO:How can I turn off the Focus Rectangle on an Infragistics Win Control?
Hi Mike,
thanks, but the manual does not describe how to show the dotted line around the checkbox itself. It only shows how to remove the dotted line.
thanks
Hi Stefan,
Oh, sorry, I misread the question. Doesn't the UltraTextEditor show a focus rectangle when it has focus? I am pretty sure it does this automatically. If not, you would have to draw it yourself using a DrawFilter.
Yes there is a focus rectangle when it has focus, but only on the text not on the box itself. So if there is no text as in my case then one can not see that the checkbox has focus. Is it possile to set a drawfilter in this case?
Yes, you could use a DrawFilter to draw a dotted rectangle (or anything else you want). If you are not familiar with DrawFilters, I recommend that you check out the Infragistics Knowledge Base. There are lots of articles with sample DrawFilters. Also, get the Infragistics UIElementViewer Utility. It's a big help when working with UIElements.
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
Please I have the same issue as you.
Please how did you implement the DrawFilter?
OysterInnovations
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