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());
}
}
}
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());
}
}
}
Comment