471,337 Members | 998 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Forcing the dotted rectangle on a button?

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
Jan 18 '06 #1
2 2672
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.

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
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

Jan 19 '06 #2
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

"Bob Powell [MVP]" wrote:
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.


Jan 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Doors of Perception | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.