S
sklett
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.Collections.Generic;
using System.Windows.Forms;
namespace PanelKeyEventExample
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private MyPanel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer 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.Dispose();
}
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.panel1 = new MyPanel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(46, 49);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(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.WriteLine("KeyUp message caught");
}
base.WndProc(ref 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.Collections.Generic;
using System.Windows.Forms;
namespace PanelKeyEventExample
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private MyPanel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer 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.Dispose();
}
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.panel1 = new MyPanel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(46, 49);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(200, 100);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(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.WriteLine("KeyUp message caught");
}
base.WndProc(ref m);
}
}
}
</code>