Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

2. Windows Forms Controls

2.4 How do I listen to windows messages in my Control?


In a derived class you should override WndProc as follows (listening to the WM_KEYUP message, for example):

[C#]
public class MyCombo : ComboBox
{
private const int WM_KEYUP = 0x101;

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == WM_KEYUP)
{
return; //ignore the keyup
}
base.WndProc(ref m);
}
}

[VB.NET]
Public Class MyTextBox
     Inherits TextBox
     Private WM_KEYUP As Integer = &H101

     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
          If m.Msg = WM_KEYUP Then
               Return 'ignore the keyup
          End If
          MyBase.WndProc(m)
     End Sub 'WndProc
End Class 'MyTextBox