Selectable User-Drawn Control

  • Thread starter Thread starter DC
  • Start date Start date
D

DC

Hi all.
I've built a class based on "Control" and I want this object of mine to be
selectable. I believe that, by default, Control is non-selectable so I used
this.SetStyle(ControlStyles.Selectable, true);

And it works fine when I use TAB key, but when I click on my object, the
focus remains on the current object.

What am I doing wrong?

TIA
 
The ControlStyles.Selectable flag is set to true by default so no need to
set it. If it were false, then the Control would not receive focus by
Tabbing to it.

I usually add the following override:

protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
if (this.CanSelect)
this.Select();
}

....although you may want to select the control on MouseDown instead of
MouseUp.

If you Set the ControlStyles.Selectable flag to false then you will notice
that, even with the code above, the control will never select by mouse or
TAB, as
this flag determines the CanSelect() methods return value.
 
Back
Top