I know that Panel (and most of it's derivitives) don't raise keyboard
events. I *really* need to catch keyboard events though so I've been
googling the topic and have found quite a few suggestions. The one
suggestion I've found that makes the most sense isn't working for me and
after this most recent failure I'm really at a loss! ;0)
I'm overriding WndProc and checking the Message.Msg property for the
WM_KEYUP message.
If anyone has any ideas for me I would really appreciate it!
Here is a complete application that shows the failure.
<code>
using System;
using System.Collecti ons.Generic;
using System.Windows. Forms;
namespace PanelKeyEventEx ample
{
public class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
private MyPanel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.IContain er components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing ">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Disp ose();
}
base.Dispose(di sposing);
}
#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 InitializeCompo nent()
{
this.panel1 = new MyPanel();
this.SuspendLay out();
//
// panel1
//
this.panel1.Loc ation = new System.Drawing. Point(46, 49);
this.panel1.Nam e = "panel1";
this.panel1.Siz e = new System.Drawing. Size(200, 100);
this.panel1.Tab Index = 0;
//
// Form1
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.panel1) ;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form1());
}
}
public class MyPanel : Panel
{
const int WM_KEYUP = 0x0101;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_KEYUP)
{
Console.WriteLi ne("KeyUp message caught");
}
base.WndProc(re f m);
}
}
}
</code>
events. I *really* need to catch keyboard events though so I've been
googling the topic and have found quite a few suggestions. The one
suggestion I've found that makes the most sense isn't working for me and
after this most recent failure I'm really at a loss! ;0)
I'm overriding WndProc and checking the Message.Msg property for the
WM_KEYUP message.
If anyone has any ideas for me I would really appreciate it!
Here is a complete application that shows the failure.
<code>
using System;
using System.Collecti ons.Generic;
using System.Windows. Forms;
namespace PanelKeyEventEx ample
{
public class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
}
private MyPanel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.IContain er components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing ">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Disp ose();
}
base.Dispose(di sposing);
}
#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 InitializeCompo nent()
{
this.panel1 = new MyPanel();
this.SuspendLay out();
//
// panel1
//
this.panel1.Loc ation = new System.Drawing. Point(46, 49);
this.panel1.Nam e = "panel1";
this.panel1.Siz e = new System.Drawing. Size(200, 100);
this.panel1.Tab Index = 0;
//
// Form1
//
this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.panel1) ;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Ena bleVisualStyles ();
Application.Set CompatibleTextR enderingDefault (false);
Application.Run (new Form1());
}
}
public class MyPanel : Panel
{
const int WM_KEYUP = 0x0101;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_KEYUP)
{
Console.WriteLi ne("KeyUp message caught");
}
base.WndProc(re f m);
}
}
}
</code>
Comment