The weirdest error - SP 2 known error???

D

Dan Ardelean

I posted a few days ago a question on firing KeyDown
events for Buttons using SP 2 - not avaible anymore. Can
somebody explain the weird behaviour of the code attached
at the end of this message (if you have installed SP2)??
If you paste the code and run you will get a form with one
button. When the button has focus the color is red. If you
press the cursor buttons while the button has focus it
will show a message with the cursor key pressed and
everything works as it has to. Now simply add (with
designer or any other way) another button to the form and
try running the program again. When I tested the fired
keycodes and sequence don't make sense. Is this a known
bug in SP 2?

Thanks:

Code:

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace ButtonFocus
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button
button1;
private System.Windows.Forms.MainMenu
mainMenu1;
private Color
unfocused_color,focused_color;

public Form1()
{
//
// Required for Windows Form
Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code
after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated
code
/// <summary>
/// Required method for Designer support -
do not modify
/// the contents of this method with the
code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new
System.Windows.Forms.MainMenu();
this.button1 = new
System.Windows.Forms.Button();
//
// button1
//
this.button1.Location = new
System.Drawing.Point(40, 40);
this.button1.Size = new
System.Drawing.Size(112, 48);
this.button1.Text = "button1";
this.button1.LostFocus += new
System.EventHandler(this.button1_LostFocus);
this.button1.GotFocus += new
System.EventHandler(this.button1_GotFocus);
//
// Form1
//
this.Controls.Add(this.button1);
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.Text = "Form1";
this.Load += new
System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the
application.
/// </summary>

static void Main()
{
Application.Run(new Form1());
}

private void button1_GotFocus(object
sender, System.EventArgs e)
{

this.button1.BackColor=this.focused_color;

}

private void button1_LostFocus(object
sender, System.EventArgs e)
{

this.button1.BackColor=this.unfocused_color;
}

private void Form1_Load(object sender,
System.EventArgs e)
{
this.button1.KeyDown+=new
KeyEventHandler(button1_KeyDown);

this.unfocused_color=this.button1.BackColor;
this.focused_color=Color.Red;

this.button1.Focus();
}

private void button1_KeyDown(object
sender, KeyEventArgs e)
{
MessageBox.Show(e.KeyCode.ToString
());
}
}
}
 
P

Paul

It's best to revert to SP1 - don't know the full bug list, and people
probably never will, but as it was recalled just forget it existed...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top