J
Jason Kyle Baginski
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.System 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.System one, which will bring up _two_
messageboxes.
Why does FlatStyle.System 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 ButtonStyleProblem
{
// 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.System will bring up the
"Activate"
// messagebox _twice_. So its a behavior only with FlatStyle.System.
// 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=FlatStyle.Standard;
this.Controls.Add(buttonStandard);
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(OnButtonClick);
buttonSystem=new Button();
buttonSystem.FlatStyle=FlatStyle.System;
this.Controls.Add(buttonSystem);
buttonSystem.Left=115;
buttonSystem.Top=2;
buttonSystem.Width=110;
buttonSystem.Height=20;
buttonSystem.Text="FlatStyle.System";
buttonSystem.KeyDown+=new KeyEventHandler(OnButton);
buttonSystem.Click+=new EventHandler(OnButtonClick);
buttonPopup=new Button();
buttonPopup.FlatStyle=FlatStyle.Popup;
this.Controls.Add(buttonPopup);
buttonPopup.Left=0;
buttonPopup.Top=25;
buttonPopup.Width=110;
buttonPopup.Height=20;
buttonPopup.Text="FlatStyle.Popup";
buttonPopup.KeyDown+=new KeyEventHandler(OnButton);
buttonPopup.Click+=new EventHandler(OnButtonClick);
buttonFlat=new Button();
buttonFlat.FlatStyle=FlatStyle.Flat;
this.Controls.Add(buttonFlat);
buttonFlat.Left=115;
buttonFlat.Top=25;
buttonFlat.Width=110;
buttonFlat.Height=20;
buttonFlat.Text="FlatStyle.Flat";
buttonFlat.KeyDown+=new KeyEventHandler(OnButton);
buttonFlat.Click+=new EventHandler(OnButtonClick);
}
private void OnButtonClick(object sender,EventArgs e)
{
MessageBox.Show("Activate");
}
private void OnButton(object sender,KeyEventArgs e)
{
if(e.KeyData==Keys.Space || e.KeyData==Keys.Enter)
button.PerformClick();
}
[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.System 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.System one, which will bring up _two_
messageboxes.
Why does FlatStyle.System 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 ButtonStyleProblem
{
// 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.System will bring up the
"Activate"
// messagebox _twice_. So its a behavior only with FlatStyle.System.
// 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=FlatStyle.Standard;
this.Controls.Add(buttonStandard);
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(OnButtonClick);
buttonSystem=new Button();
buttonSystem.FlatStyle=FlatStyle.System;
this.Controls.Add(buttonSystem);
buttonSystem.Left=115;
buttonSystem.Top=2;
buttonSystem.Width=110;
buttonSystem.Height=20;
buttonSystem.Text="FlatStyle.System";
buttonSystem.KeyDown+=new KeyEventHandler(OnButton);
buttonSystem.Click+=new EventHandler(OnButtonClick);
buttonPopup=new Button();
buttonPopup.FlatStyle=FlatStyle.Popup;
this.Controls.Add(buttonPopup);
buttonPopup.Left=0;
buttonPopup.Top=25;
buttonPopup.Width=110;
buttonPopup.Height=20;
buttonPopup.Text="FlatStyle.Popup";
buttonPopup.KeyDown+=new KeyEventHandler(OnButton);
buttonPopup.Click+=new EventHandler(OnButtonClick);
buttonFlat=new Button();
buttonFlat.FlatStyle=FlatStyle.Flat;
this.Controls.Add(buttonFlat);
buttonFlat.Left=115;
buttonFlat.Top=25;
buttonFlat.Width=110;
buttonFlat.Height=20;
buttonFlat.Text="FlatStyle.Flat";
buttonFlat.KeyDown+=new KeyEventHandler(OnButton);
buttonFlat.Click+=new EventHandler(OnButtonClick);
}
private void OnButtonClick(object sender,EventArgs e)
{
MessageBox.Show("Activate");
}
private void OnButton(object sender,KeyEventArgs e)
{
if(e.KeyData==Keys.Space || e.KeyData==Keys.Enter)
button.PerformClick();
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}