Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello,
I'm working with a windows forms and c# in visual studio 2008.

Problem:
I have an image in a button and I want to focus this control with tab key. Once the button is focused, a gray square appear around the button.

Question:
How can I delete this square and don't have any style when the button is focused?


Thank u.
Posted
Updated 19-Feb-11 8:07am
v4

How do you create the "gray square" in the first place. There is always the OnLostFocus Method.
 
Share this answer
 
Comments
bocabu 19-Feb-11 12:59pm    
The "gray square" is created automatic. For example, in web pages when a control is focused, it has a dot's line around the control.

I want to delete this square.

thank u!
fjdiewornncalwe 21-Feb-11 11:57am    
I was under the impression that the "gray square" was something you were putting there manually.
In this situation, just remove the focus from the control and it will go away. If something is added automatically by the system, let the system remove it.
bocabu 21-Feb-11 12:01pm    
But if I remove the focus I can't use tab key to move for each object.

tanks
Espen Harlinn 20-Feb-11 9:59am    
Good point. my 5
This is the default rendering for the Button class. If you want to remove that, then you will need to provide your own drawing functions for the button.

You may need ButtonRenderer and this could help:
http://msdn.microsoft.com/fr-fr/library/system.windows.forms.buttonrenderer(v=vs.80).aspx[^]
 
Share this answer
 
Comments
bocabu 19-Feb-11 13:34pm    
Is not any possible way to solve it with out draw again the control?
Olivier Levrey 20-Feb-11 7:57am    
There is no option in the Button class that says "do not draw the focus rect", so you will have to draw the button by yourself, or live with the defaults.
Even though I never used the ButtonRenderer class by myself, you can probably call the default drawing functions and customize only the focus part.
Sergey Alexandrovich Kryukov 19-Feb-11 21:05pm    
This is the best answer, and this class is the best helper class for the purpose, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900