473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Tab and focus rectangle question

I created a form and put a button and a label on it. I set the tabstops to
false. When I first run it I can click the button and there is no focus
rectangle. Which is what I want. However, if I press the tab key nothing
initially seems to happen, I know nothing should because I set the tabstop
to false, but to my surprise, when I then click the button again a focus
rectangle appears. This I do not want. Any Ideas on how to stop this
behaviour? Here's some code I tried. I also do not want the focus to stay on
the button during or after I click it which is why I set the focus to the
label. But the rectangles stays. Ugly...
Thanks for the help. John.

namespace WindowsFormsApplication3

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

label1.Focus();

}

private void button1_MouseUp(object sender, MouseEventArgs e)

{

label1.Focus();

}

}

}
Jul 18 '08 #1
1 2675
On Fri, 18 Jul 2008 14:35:47 -0700, john ciriello <j.********@comcast.net>
wrote:
I created a form and put a button and a label on it. I set the tabstops
to
false. When I first run it I can click the button and there is no focus
rectangle. Which is what I want. However, if I press the tab key nothing
initially seems to happen, I know nothing should because I set the
tabstop
to false, but to my surprise, when I then click the button again a focus
rectangle appears. This I do not want. Any Ideas on how to stop this
behaviour?
Assuming the Label instance was enabled, you should be able to force the
focus to it by handling the Enter event on the Button instance and calling
label1.Focus(). Handling the Click and MouseUp events isn't the correct
way, because that's not precisely where focus is set.

That said, if what you want is specifically a button that won't accept
focus, IMHO a better way to do it is to create your own Button sub-class
in which you set the ControlStyles.Selectable style to "false". Then the
button will never receive focus in the first place.

All that said, I question your decision to make the button so that it
won't receive focus. Focus is a very important part of allowing a Windows
application to be accessible by alternative means of input. You cannot
assume that the user has access or the ability to use a mouse. Windows
provides some surrogate input methods for dealing with applications that
are rude enough to require a mouse for input, but it's better for your
application to simply not require a mouse in the first place.

Pete
Jul 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Chris | last post by:
I'm using eight links listed horizontally as a menu on my site. I'm using font-variant:small-caps and they are padded so that they mimic buttons. My gripe is with the way IE handles the focus...
0
by: Steve Bezner | last post by:
I have an issue in which a link label on a windows form does not draw the focus rectangle if you programmatically force it to have focus via the Control.Focus() method. To duplicate, create...
0
by: Stephen Bedford | last post by:
I am developing an application that is primarily keyboard not mouse driven. Navigation is very difficult within some controls (list boxes, radio groups etc) unless the focus rectangle is visible. ...
2
by: Peter | last post by:
I have the following code where I get Rectangle Bounds of a text box, but I have other controls on my Windows Form like ListBoxes and Combo Boxes, I want to get Rectangle Bounds when I Enter the...
1
by: cider123 | last post by:
I've tried working with the SelectedIndices and Items.Selected attributes to get the problem to go away, but not having any luck. Questions I have are: 1) How do you move (using code) the...
1
by: Jason | last post by:
I am creating my own tab control in vb.net. I am inheriting System.Windows.Forms.TabControl. I want to provide a property that disables or enables the focus rectangle being drawn on the tabs....
4
by: SJ | last post by:
Hi all, I have come across a weird problem when attempting to automatically set the focus in a vb.net form to a checkbox control... In my form I have (on a tab page in a tab control) several...
5
by: Matt B | last post by:
I know this is a bit of nonstandard behavior, but I would like the Enter key to move focus through a group of radiobuttons without selecting them. The user would then have to use Space or actually...
1
by: john ciriello | last post by:
Hey Peter, if you see this I tried to respond but the server rejected the request. Here's my reply to your responce. Thanks. Hi Peter, thanks for the reply. I should be more specific though. If...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.