Skip to content

Dotted Focus around the checkbox

New Discussion
Mike
Mike asked on Jun 4, 2009 2:24 PM

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

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Nov 18, 2008 2:55 PM
    • 0
      Mike
      Mike answered on Nov 18, 2008 3:13 PM

      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

      Stefan

      • 0
        Mike Saltzman
        Mike Saltzman answered on Nov 18, 2008 3:34 PM

         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. 

      • 0
        Mike
        Mike answered on Nov 18, 2008 4:03 PM

        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?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Nov 18, 2008 7:32 PM

        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. 

      • 0
        Mike
        Mike answered on Nov 25, 2008 8:11 AM

        Hi,

        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:

         

        public bool DrawElement(Infragistics.Win.DrawPhase drawPhase, ref Infragistics.Win.UIElementDrawParams drawParams)

        {

        if (drawParams.ControlElement.Control.Focused)

        {

        System.Drawing.Rectangle elementRect = drawParams.Element.Rect;

        drawParams.Graphics.DrawRectangle(

        new System.Drawing.Pen(System.Drawing.Color.Red), elementRect.X , elementRect.Y + 1, elementRect.Width, elementRect.Height);elementRect.Location = new System.Drawing.Point( elementRect.X + 1 , elementRect.Y);return false;

        }

        elsereturn false;

        }

        public Infragistics.Win.DrawPhase GetPhasesToFilter(ref Infragistics.Win.UIElementDrawParams drawParams)

        {

        if (drawParams.Element is Infragistics.Win.CheckIndicatorUIElement)

        return Infragistics.Win.DrawPhase.BeforeDrawElement;

        elsereturn Infragistics.Win.DrawPhase.None;

        }

        #endregion

        }

      • 0
        Matt Snyder
        Matt Snyder answered on Nov 25, 2008 2:31 PM

        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

      • 0
        Oyster
        Oyster answered on Apr 14, 2009 8:40 PM

        Please I have the same issue as you.

        Please how did you implement the DrawFilter?

        OysterInnovations

      • 0
        Oyster
        Oyster answered on Apr 14, 2009 10:00 PM

        Thanks. I think I figured this out

      • 0
        Marcel
        Marcel answered on Jun 4, 2009 2:24 PM

        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
                }
            }

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Mike
Favorites
0
Replies
10
Created On
Jun 04, 2009
Last Post
17 years, 5 months ago

Suggested Discussions

Tags

No tags

Created by

Created on

Jun 4, 2009 2:24 PM

Last activity on

Jun 4, 2009 2:24 PM