Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable focus cues on a SplitContainer

How can I disable the focus cues on a SplitContainer? I ask because I'd rather draw them myself using OnPaint in order to make it look somewhat smoother.

I tried this:

    protected override bool ShowFocusCues
    {
        get
        {
            return false;
        }
    }

And this is my control:

    public class cSplitContainer : SplitContainer
    {
        private bool IsDragging;

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (!IsSplitterFixed) IsDragging = true;
            Invalidate();
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (IsDragging)
            {
                IsDragging = false;
                IsSplitterFixed = false;
            }
        }
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (IsDragging)
            {
                IsSplitterFixed = true;
                if (e.Button == MouseButtons.Left)
                {
                    if (Orientation == Orientation.Vertical)
                    {
                        if (e.X > 0 && e.X < Width) SplitterDistance = e.X;
                    }
                    else
                    {
                        if (e.Y > 0 && e.Y < Height) SplitterDistance = e.Y;
                    }
                }
                else
                {
                    IsDragging = false;
                    IsSplitterFixed = false;
                }
            }
        }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            base.OnPaint(e);
            if (IsDragging)
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(127, 0, 0, 0)), Orientation == Orientation.Horizontal ? new Rectangle(0, SplitterDistance, Width, SplitterWidth) : new Rectangle(SplitterDistance, 0, SplitterWidth, Height));
            }
        }
    }

but it didn't work. I also tried some other methods mentioned before, but I'm still getting focus cues.

like image 693
bytecode77 Avatar asked Mar 14 '12 18:03

bytecode77


1 Answers

I don't think what you are seeing is the FocusCue so much as a floating window that is used to move the slider.

If keyboard access isn't important, you can try making it unselectable:

public class MySplit : SplitContainer {

  public MySplit() {
    this.SetStyle(ControlStyles.Selectable, false);
  }

  protected override void OnPaint(PaintEventArgs e) {
    e.Graphics.Clear(Color.Red);
  }
}

This prevents the SplitContainer from getting focus, but your mouse can still interact with it.

like image 80
LarsTech Avatar answered Sep 16 '22 16:09

LarsTech