F
Frankie Leung
Dear all,
I am writing a program (game) which will start processing when the user
had select an option from the ComboBox. Meanwhile, I want to make the
program to be able to listen to the user input whenever the application
is running. The execution of the KeyPress event from the Windows Form
must be processed first, even if other functions is processing.
However, the result of the running program does not seems to be behave
in this way. The program does not respond to the user input while it is
processing another function. Here is the code snippet for this program.
Extra code has been trimmed for simplicity and easy reading.
using System;
namespace AGame
{
partial class AGameMainFormDesigner : System.Windows.Forms.Form
{
// Constructor
public AGameMainFormDesigner (...) {
...
this.InitializeComponent();
}
void InitializeComponent()
{
this.cmbSelectLevel = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
// cmbSelectLevel
this.cmbSelectLevel.SelectedIndexChanged += new
System.EventHandler(this.cmbSelectLevel_SelectedIndexChanged);
// SpeechTypingGameMainFormDesigner
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.SpeechTypingGameMainFormDesignerKeyPress);
this.ResumeLayout(false);
}
private System.Windows.Forms.ComboBox cmbSelectLevel;
// Event functions
void cmbSelectLevel_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.PlayGame();
}
void SpeechTypingGameMainFormDesignerKeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
// Display the user input in the Windows Form
...
}
private void PlayGame() {
while (cond) {
// Do something
...
}
}
}
}
Any help will be greatly appreciated.
Best regards,
Frankie
I am writing a program (game) which will start processing when the user
had select an option from the ComboBox. Meanwhile, I want to make the
program to be able to listen to the user input whenever the application
is running. The execution of the KeyPress event from the Windows Form
must be processed first, even if other functions is processing.
However, the result of the running program does not seems to be behave
in this way. The program does not respond to the user input while it is
processing another function. Here is the code snippet for this program.
Extra code has been trimmed for simplicity and easy reading.
using System;
namespace AGame
{
partial class AGameMainFormDesigner : System.Windows.Forms.Form
{
// Constructor
public AGameMainFormDesigner (...) {
...
this.InitializeComponent();
}
void InitializeComponent()
{
this.cmbSelectLevel = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
// cmbSelectLevel
this.cmbSelectLevel.SelectedIndexChanged += new
System.EventHandler(this.cmbSelectLevel_SelectedIndexChanged);
// SpeechTypingGameMainFormDesigner
this.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.SpeechTypingGameMainFormDesignerKeyPress);
this.ResumeLayout(false);
}
private System.Windows.Forms.ComboBox cmbSelectLevel;
// Event functions
void cmbSelectLevel_SelectedIndexChanged(object sender,
System.EventArgs e)
{
this.PlayGame();
}
void SpeechTypingGameMainFormDesignerKeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
// Display the user input in the Windows Form
...
}
private void PlayGame() {
while (cond) {
// Do something
...
}
}
}
}
Any help will be greatly appreciated.
Best regards,
Frankie