Forcing the dotted rectangle on a button?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Before I go into detail, is there any way to force a button to get that
dotted box on it that shows it's in focus? Just saying btn1.Focus(); isn't
working for me. Btn1 is definitely the thing being focused on, but you
wouldn't know by just looking at it. And it seems that the only way to get a
button to show highlight is to Tab into it.

So, the weird details...
Say I put a custom button on my form (and gave it tabstop 1). I then add a
textbox with tabstop 2. And finally another button (tabstop 3). If I click in
the textbox and press the Tab key, the 2nd button gets that dotted line, no
problem. Same goes if I press Shift-Tab (the 1st button shows focus). I made
the textbox so that it recognizes if the up or down keys are hit, so when I'm
in the textbox and press the up key, I say:
if (e.KeyCode == Keys.Up){SendKeys.Send("+{Tab}");}
and have no problem here either - the first button shows focus.
But if down is pressed:
if (e.KeyCode == Keys.Down){SendKeys.Send("{Tab}");}
it freaks out and everything freezes so that I have to open task manager to
close it down.

One other thing - if a button has been highlighted (tabbed into) once,
saying just btn1.Focus(); is enough. But, of course, I can't be sure that tab
will always be pressed.
Hope this makes sense.
Thanks for any help on this!
Mel
 
When you say "custom button" are you certain that this control follows the
design rules for UI feedback?

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Hi!
I followed the example to create a toggle button in the Microsoft Visual C#
..Net Step By Step version 2003 book - Chapter 23 "Creating GUI Components"
(page 427), so I'm guessing I followed the rules (I'm still kind of new and
don't know all the rules yet). After I asked the question, I did realize
that my button is really descended from a CheckBox, but I don't think that
would make any difference (?), and I still don't think it would explain the
strange behavior of accepting sending a +Tab but not a Tab (I'm trying to
work around another strange behavior at the moment that's a result of these
'buttons'). Anyway, thanks very much for trying to help me with this!
Cheers,
Mel
 
Back
Top