Click here to Skip to main content
15,943,477 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Sir, I hav winform with flat style buttons. when i click on buttons,border is apperaing around button.if i click out side, it disappearing.and when i press space bar, automatically button click event is firing. i tried almostly .but i cant solve this pls help Sir. My form controls: "one panel,one treeview, 3 buttons(flat style)"
Updated 1-Dec-14 17:35pm
Sergey Alexandrovich Kryukov 29-Nov-14 1:38am    
Why? why?!
Anyway, all visual effects depends on what is your UI library and application type.
When you say, for example, "Button", the question is: which one? always specify full type name. Without it, this question makes no sense.
NarasinghRao 29-Nov-14 1:50am    
it is windows application vs-2012.c# 4.0 i have placed all buttons in panel.
Sergey Alexandrovich Kryukov 30-Nov-14 21:51pm    
"Button"? Full type name, please. "Panel"? Full type name, please.

I think you are asking about first time you click the Button .
Later when user click on Space bar the button event is triggering again.

Yes it will happen .When ever you click on Button the focus will be set to button .So when user press Space bar the button click event triggers.

To avoid this in your button click
first write your code and then set focus to some lable ,textbox or other controls as you wish for example see the below code. in button click.

private void button1_Click(object sender, EventArgs e)

here in button click event i display the message box and set the focus to label.

If press space bar the button event will not triger .
Hope you get your solution :)
Share this answer
NarasinghRao 2-Dec-14 1:22am    
Sir, if you dont mine just do it
Ex: take winform-> 1st add treeview->add buttons make them flatstyle->run apliation:
Now, 1st click on treeview next press any LETTER ON KEYBORD next click button. if you observe some border wil appear around buttontext. i want to remove that..
syed shanu 2-Dec-14 1:28am    
Yes i try your reuirement as i told you one simple solution is you can just set focus to some other control in button click event.
I add tree view and 3 buttons.
for button 1 i write below code.
private void button1_Click(object sender, EventArgs e)
remaing 2 buttons didnt write the above code.
Now for button 1 there is no inner border and for remaining buttons there is the inner border.
NarasinghRao 2-Dec-14 1:40am    
Thank You Sir..its good..but when mouse click,border is firing.cant we hide that?

i solved like..1ST i added buttons NEXT treeview,now there is no border at mouse click..
syed shanu 2-Dec-14 1:48am    
yes if you only mouse click event.Then insted of Button Click Event .you can use the Mouse Down Event.this will avoid the border even when you click.

private void button1_MouseDown(object sender, MouseEventArgs e)
NarasinghRao 2-Dec-14 2:06am    
ok.but user cant get that button was clicked..and in flat appearance MouseDownBackColor is not firing.
Space bar should invoke the Click event on the button. This is expected effect which you should not avoid; otherwise you would confuse you users.

When you ask such questions, always specify full type name. There are several different unrelated by similar type using the type name "Button"; the same goes for "Panel" and many other types.

Share this answer
NarasinghRao 30-Nov-14 23:38pm    
Sir, pls is there any way to post image or pic in our comments place...i wil upload image of button,it wil give you clear undastnd.." I took button and panel from toolbox and i changed button style as flat. the lines are raising only when i click panel first later button.and the button event is automatically focusing so if i press spacebar or enter key automatically buttonClick event raising...
Sergey Alexandrovich Kryukov 30-Nov-14 23:49pm    
Sorry, there is no such way. You can reference external Web resource. I think accurate description in words is also possible, just please do it thoroughly.
NarasinghRao 1-Dec-14 0:12am    
i hav button (btnCreate) and Panel(pnlBatch)..i placed button in panel..button is exactly looks like our "reply" button Style.once i click panel and later button the border is appearing around button text.agian i click outside of button it is disappearing. that is my Problem..still i m thinking why it is coming like not getting exact ans.
Sergey Alexandrovich Kryukov 1-Dec-14 10:26am    
What do you exactly mean by "Button"?! I'm asking again and again. Is it so difficult to tell us its exact full type name. If you have some unexpected effect, create some very short but comprehensive code sample manifesting this problem. Therefore, it should not be application. White this code focusing only on one problem. Add it using "Improve question".
NarasinghRao 1-Dec-14 23:27pm    
I fully thanks to you Sir for Your Valuable Replys. at last i got solution for My problem."its pretty simple, only treeview is effecting that border to buttons.
if you add treeview after all buttons, it wont give border, but treeview first later buttons, than buttons getting border.
ex:. new winform->add treeview->add button(change it flat style)->run application->click on treeview->press any key on keybord->now click on button. button wil get some border definetly..

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