473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 WindowsFormsApp lication3

{

public partial class Form1 : Form

{

public Form1()

{

InitializeCompo nent();

}

private void button1_Click(o bject sender, EventArgs e)

{

label1.Focus();

}

private void button1_MouseUp (object sender, MouseEventArgs e)

{

label1.Focus();

}

}

}
Jul 18 '08 #1
1 2719
On Fri, 18 Jul 2008 14:35:47 -0700, john ciriello <j.********@com cast.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.S electable 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
10560
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 rectangle on these links. It insists on drawing this crazy shape that traces the text, which with small caps looks rather assinine. Firefox handles the same task very gracefully (yeah Gecko!) and I would like to force IE to do the same. The site...
0
2166
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 a new windows app, place a button and a link label on the form. In the button click event, place the following code, this.linkLabel1.Focus(). Run the app and press tab between the two controls and you notice that the link label has the focus...
0
2155
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. When an application starts the focus rectangle for a control is never visible and only becomes visible once the TAB key is pressed. After that everything works OK. In a list box I have looked at the ChangeUICues event of the control and there is a...
2
5961
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 control regardless which control I Enter. How would I code Form1_Paint method so rect can equal the Bounds of the current control with focus? private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Rectangle rect =...
1
5058
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 focus Rectangle when your Selected Index changes ? 2) If there are no selected rows, can that focus rectangle be removed? 3) What other quirks exist in this simple example I might need to code for ?
1
5743
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. Setting the DrawMode to OwnerFixed and adding the drawing methods in overrides OnDrawItem doesn't seem to do it. The focus rectangle is drawn no matter what is drawn in the OnDrawItem event. How can I prevent the focus rectangle from being drawn? ...
4
3952
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 textboxes and a checkbox. The behaviour I want from my app is as follows:- When the textbox (which is prior in tab order to the tab control) has been filled with a certain length of text by the user, the focus is
5
11657
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 click to select one of the radiobuttons to select. The default behavior of Focus() seems to also select the radiobutton, but I can't seem to find what is causing this to happen. I would like very much to seperate the Focus and the selection....
1
1618
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 you run Microsofts calculator, under accessories, in both standard and scientific you will find that they(Microsoft) have disabled the Tab key completely, when the buttons are clicked there is no focus rectangle and when the mouse moves away, the...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.