473,738 Members | 4,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button FlatStyle.Syste m spacebar behavior

Here's a little test app to demonstrate a problem I'm having.

It creates four buttons, each one with the different FlatStyle types
available. Three of them behave exactly the same way(and the way I'd
anticipate), but the FlatStyle.Syste m one does not.

If you click on any of the buttons, use the enter key, or the
spacebar, they will bring up a messagebox that says "Activate".
Except the FlatStyle.Syste m one, which will bring up _two_
messageboxes.

Why does FlatStyle.Syste m fire twice, when all of the other
FlatStyle's only fire once?

Below is the simplest example to recreate the problem. For reference,
its been tested under XP Pro, XP Home, and 98(yes..98). All 1.1
framework. They all act the exact same way.

using System;
using System.Windows. Forms;

namespace ButtonStyleProb lem
{
// create four buttons showing off each of the FlatStyle's
// If you tab between the different buttons, then hit the space bar
// all of the buttons will bring up a messagebox that says
"Activate".
// The problem is that the FlatStyle.Syste m will bring up the
"Activate"
// messagebox _twice_. So its a behavior only with FlatStyle.Syste m.
// The strangest thing is this test program behaves the same way
under XP and 98
// so its not an XP theme problem.
public class Form1 : System.Windows. Forms.Form
{
public Button buttonStandard;
public Button buttonSystem;
public Button buttonPopup;
public Button buttonFlat;

public Form1()
{
this.Width=240;
this.Height=80;

buttonStandard= new Button();
buttonStandard. FlatStyle=FlatS tyle.Standard;
this.Controls.A dd(buttonStanda rd);
buttonStandard. Left=0;
buttonStandard. Top=2;
buttonStandard. Width=110;
buttonStandard. Height=20;
buttonStandard. Text="FlatStyle .Standard";
buttonStandard. KeyDown+=new KeyEventHandler (OnButton);
buttonStandard. Click+=new EventHandler(On ButtonClick);

buttonSystem=ne w Button();
buttonSystem.Fl atStyle=FlatSty le.System;
this.Controls.A dd(buttonSystem );
buttonSystem.Le ft=115;
buttonSystem.To p=2;
buttonSystem.Wi dth=110;
buttonSystem.He ight=20;
buttonSystem.Te xt="FlatStyle.S ystem";
buttonSystem.Ke yDown+=new KeyEventHandler (OnButton);
buttonSystem.Cl ick+=new EventHandler(On ButtonClick);

buttonPopup=new Button();
buttonPopup.Fla tStyle=FlatStyl e.Popup;
this.Controls.A dd(buttonPopup) ;
buttonPopup.Lef t=0;
buttonPopup.Top =25;
buttonPopup.Wid th=110;
buttonPopup.Hei ght=20;
buttonPopup.Tex t="FlatStyle.Po pup";
buttonPopup.Key Down+=new KeyEventHandler (OnButton);
buttonPopup.Cli ck+=new EventHandler(On ButtonClick);

buttonFlat=new Button();
buttonFlat.Flat Style=FlatStyle .Flat;
this.Controls.A dd(buttonFlat);
buttonFlat.Left =115;
buttonFlat.Top= 25;
buttonFlat.Widt h=110;
buttonFlat.Heig ht=20;
buttonFlat.Text ="FlatStyle.Fla t";
buttonFlat.KeyD own+=new KeyEventHandler (OnButton);
buttonFlat.Clic k+=new EventHandler(On ButtonClick);
}
private void OnButtonClick(o bject sender,EventArg s e)
{
MessageBox.Show ("Activate") ;
}

private void OnButton(object sender,KeyEvent Args e)
{
if(e.KeyData==K eys.Space || e.KeyData==Keys .Enter)
button.PerformC lick();
}
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
}
}
Nov 15 '05 #1
3 5137
Unfortunately - this worked fine for me with the exception of this code:
private void OnButton(object sender,KeyEvent Args e)

{

if(e.KeyData==K eys.Space || e.KeyData==Keys .Enter)

button.PerformC lick();

}

This doesn't work because you didn't define "button." --- can hyou clarify
what you are doing here and what is "PerformClick() "

Brian Patterson

"Jason Kyle Baginski" <nx*****@winvoi ce.com> wrote in message
news:bd******** *************** ***@posting.goo gle.com...
Here's a little test app to demonstrate a problem I'm having.

It creates four buttons, each one with the different FlatStyle types
available. Three of them behave exactly the same way(and the way I'd
anticipate), but the FlatStyle.Syste m one does not.

If you click on any of the buttons, use the enter key, or the
spacebar, they will bring up a messagebox that says "Activate".
Except the FlatStyle.Syste m one, which will bring up _two_
messageboxes.

Why does FlatStyle.Syste m fire twice, when all of the other
FlatStyle's only fire once?

Below is the simplest example to recreate the problem. For reference,
its been tested under XP Pro, XP Home, and 98(yes..98). All 1.1
framework. They all act the exact same way.

using System;
using System.Windows. Forms;

namespace ButtonStyleProb lem
{
// create four buttons showing off each of the FlatStyle's
// If you tab between the different buttons, then hit the space bar
// all of the buttons will bring up a messagebox that says
"Activate".
// The problem is that the FlatStyle.Syste m will bring up the
"Activate"
// messagebox _twice_. So its a behavior only with FlatStyle.Syste m.
// The strangest thing is this test program behaves the same way
under XP and 98
// so its not an XP theme problem.
public class Form1 : System.Windows. Forms.Form
{
public Button buttonStandard;
public Button buttonSystem;
public Button buttonPopup;
public Button buttonFlat;

public Form1()
{
this.Width=240;
this.Height=80;

buttonStandard= new Button();
buttonStandard. FlatStyle=FlatS tyle.Standard;
this.Controls.A dd(buttonStanda rd);
buttonStandard. Left=0;
buttonStandard. Top=2;
buttonStandard. Width=110;
buttonStandard. Height=20;
buttonStandard. Text="FlatStyle .Standard";
buttonStandard. KeyDown+=new KeyEventHandler (OnButton);
buttonStandard. Click+=new EventHandler(On ButtonClick);

buttonSystem=ne w Button();
buttonSystem.Fl atStyle=FlatSty le.System;
this.Controls.A dd(buttonSystem );
buttonSystem.Le ft=115;
buttonSystem.To p=2;
buttonSystem.Wi dth=110;
buttonSystem.He ight=20;
buttonSystem.Te xt="FlatStyle.S ystem";
buttonSystem.Ke yDown+=new KeyEventHandler (OnButton);
buttonSystem.Cl ick+=new EventHandler(On ButtonClick);

buttonPopup=new Button();
buttonPopup.Fla tStyle=FlatStyl e.Popup;
this.Controls.A dd(buttonPopup) ;
buttonPopup.Lef t=0;
buttonPopup.Top =25;
buttonPopup.Wid th=110;
buttonPopup.Hei ght=20;
buttonPopup.Tex t="FlatStyle.Po pup";
buttonPopup.Key Down+=new KeyEventHandler (OnButton);
buttonPopup.Cli ck+=new EventHandler(On ButtonClick);

buttonFlat=new Button();
buttonFlat.Flat Style=FlatStyle .Flat;
this.Controls.A dd(buttonFlat);
buttonFlat.Left =115;
buttonFlat.Top= 25;
buttonFlat.Widt h=110;
buttonFlat.Heig ht=20;
buttonFlat.Text ="FlatStyle.Fla t";
buttonFlat.KeyD own+=new KeyEventHandler (OnButton);
buttonFlat.Clic k+=new EventHandler(On ButtonClick);
}
private void OnButtonClick(o bject sender,EventArg s e)
{
MessageBox.Show ("Activate") ;
}

private void OnButton(object sender,KeyEvent Args e)
{
if(e.KeyData==K eys.Space || e.KeyData==Keys .Enter)
button.PerformC lick();
}
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
}
}

Nov 15 '05 #2
PerformClick() is a public method defined in IButtonControl which is called
automatically when you press enter... To make that line compile, change
button.PerformC lick(); to ((Button)sender ).PerformClick( );

But, since PerformClick() is already called automatically when you press
enter, calling that method manually, as you do, will of course result in it
being called twice.

I'm not sure why you have a handler for the KeyDown event, since pressing
space or enter on a focused button will raise its Click event without any
additional coding. You basically have 2 event handlers calling the same
method.

All you need to do is create a handler only for the Click event and all will
be well...
"Brian Patterson" <GO************ *******@IHATESP AMmchsi.com.NOS PAM> wrote in
message news:Oq******** ******@TK2MSFTN GP11.phx.gbl...
Unfortunately - this worked fine for me with the exception of this code:
private void OnButton(object sender,KeyEvent Args e)

{

if(e.KeyData==K eys.Space || e.KeyData==Keys .Enter)

button.PerformC lick();

}

This doesn't work because you didn't define "button." --- can hyou clarify
what you are doing here and what is "PerformClick() "

Brian Patterson

"Jason Kyle Baginski" <nx*****@winvoi ce.com> wrote in message
news:bd******** *************** ***@posting.goo gle.com...
Here's a little test app to demonstrate a problem I'm having.

It creates four buttons, each one with the different FlatStyle types
available. Three of them behave exactly the same way(and the way I'd
anticipate), but the FlatStyle.Syste m one does not.

If you click on any of the buttons, use the enter key, or the
spacebar, they will bring up a messagebox that says "Activate".
Except the FlatStyle.Syste m one, which will bring up _two_
messageboxes.

Why does FlatStyle.Syste m fire twice, when all of the other
FlatStyle's only fire once?

Below is the simplest example to recreate the problem. For reference,
its been tested under XP Pro, XP Home, and 98(yes..98). All 1.1
framework. They all act the exact same way.

using System;
using System.Windows. Forms;

namespace ButtonStyleProb lem
{
// create four buttons showing off each of the FlatStyle's
// If you tab between the different buttons, then hit the space bar
// all of the buttons will bring up a messagebox that says
"Activate".
// The problem is that the FlatStyle.Syste m will bring up the
"Activate"
// messagebox _twice_. So its a behavior only with FlatStyle.Syste m.
// The strangest thing is this test program behaves the same way
under XP and 98
// so its not an XP theme problem.
public class Form1 : System.Windows. Forms.Form
{
public Button buttonStandard;
public Button buttonSystem;
public Button buttonPopup;
public Button buttonFlat;

public Form1()
{
this.Width=240;
this.Height=80;

buttonStandard= new Button();
buttonStandard. FlatStyle=FlatS tyle.Standard;
this.Controls.A dd(buttonStanda rd);
buttonStandard. Left=0;
buttonStandard. Top=2;
buttonStandard. Width=110;
buttonStandard. Height=20;
buttonStandard. Text="FlatStyle .Standard";
buttonStandard. KeyDown+=new KeyEventHandler (OnButton);
buttonStandard. Click+=new EventHandler(On ButtonClick);

buttonSystem=ne w Button();
buttonSystem.Fl atStyle=FlatSty le.System;
this.Controls.A dd(buttonSystem );
buttonSystem.Le ft=115;
buttonSystem.To p=2;
buttonSystem.Wi dth=110;
buttonSystem.He ight=20;
buttonSystem.Te xt="FlatStyle.S ystem";
buttonSystem.Ke yDown+=new KeyEventHandler (OnButton);
buttonSystem.Cl ick+=new EventHandler(On ButtonClick);

buttonPopup=new Button();
buttonPopup.Fla tStyle=FlatStyl e.Popup;
this.Controls.A dd(buttonPopup) ;
buttonPopup.Lef t=0;
buttonPopup.Top =25;
buttonPopup.Wid th=110;
buttonPopup.Hei ght=20;
buttonPopup.Tex t="FlatStyle.Po pup";
buttonPopup.Key Down+=new KeyEventHandler (OnButton);
buttonPopup.Cli ck+=new EventHandler(On ButtonClick);

buttonFlat=new Button();
buttonFlat.Flat Style=FlatStyle .Flat;
this.Controls.A dd(buttonFlat);
buttonFlat.Left =115;
buttonFlat.Top= 25;
buttonFlat.Widt h=110;
buttonFlat.Heig ht=20;
buttonFlat.Text ="FlatStyle.Fla t";
buttonFlat.KeyD own+=new KeyEventHandler (OnButton);
buttonFlat.Clic k+=new EventHandler(On ButtonClick);
}
private void OnButtonClick(o bject sender,EventArg s e)
{
MessageBox.Show ("Activate") ;
}

private void OnButton(object sender,KeyEvent Args e)
{
if(e.KeyData==K eys.Space || e.KeyData==Keys .Enter)
button.PerformC lick();
}
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
}
}


Nov 15 '05 #3
> I'm not sure why you have a handler for the KeyDown event, since pressing
space or enter on a focused button will raise its Click event without any
additional coding. You basically have 2 event handlers calling the same
method.


This was the simplest example code to generate the behavior I was
experiencing with a much more complicated DataGrid custom column where
I'm intercepting keyboard behavior. My code had worked fine until I
put FlatStyle.Syste m in for the button. So this is the test app.

Why do all of the other button flatstyle's give the desired action(one
text box), but FlatStyle.Syste m(XP or 98) fires it twice, while all
the other buttons that are written the exact same way, fire once? I
know the example code is ugly, but it's to demonstrate odd behavior
for setting one attribute that should have nothing to do with events.
Nov 15 '05 #4

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

Similar topics

16
2556
by: MLH | last post by:
In Access 97 and Access 2.0 applications, if a command button has the focus, the spacebar will 'PRESS" the key. How does one go about disabling this annoying BEATURE?
3
6080
by: Zürcher See | last post by:
Someone has implemented a Datagrid Button for the Windows.Form?
2
5027
by: Curtis Wellborn | last post by:
Hey, I have come into a bit of a problem. When Flatsyle is on system it will not show my images that i have set in image list or just in image. Also somethings i have found online do not work because i coded it to change the flatstyles(if needed) to whatever theme the user is using. This is the code that effects it: private void RecursivelyFormatForWinXP(Control control) {
18
3069
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to button style, I must use a System.Windows.Forms.Button. I can not find a way to tell when it is momentaraly pressed. I tried calling the API SendMessage with the button handle and BM_GETSTATE to get the state of the button. This will only return...
4
2628
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
4
1399
by: Mick Doherty | last post by:
Steps to reproduce: Inherit from button. Add button to project's form. Run project. Make button Default. Press and Hold SpaceBar (so button is pressed) Move Mouse. Release SpaceBar.
3
1268
by: Mick Doherty | last post by:
Minimal Code and steps needed to show problem. Inherit from Button and set Region as below. \\\ Protected Overrides Sub OnPaint(ByVal pevent as PaintEventArgs) MyBase.OnPaint(pevent) Me.Region = New Region(New Rectangle(5, 5, Width - 10, Height - 10)) End Sub ///
1
2712
by: siliconpi | last post by:
I'm looking for the simplest and cleanest way of having 10 buttons on a form, on which if I move my mouse over, a label's text changes as specified. I'm using Visual Basic .NET and I'm not too familiar with its intricacies, so I'm getting a bunch of errors on certain scenarios. The code below works fine but breaks if I click on Button1 a few times without moving the program window ----------
5
5431
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
0
8969
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
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9208
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
6751
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
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
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...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
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.