Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I process Windows messages in a control?

Override the control's WndProc method. This sample shows a custom control that is a ComboBox that discards the WM_KEYUP message.

[C#]

using System.Windows.Forms;

public class ComboBoxWithNoKeyUp : ComboBox
{
  private const int WM_KEYUP = 0x101;

  protected override void WndProc(ref Message m)
  {
    if ( m.Msg == WM_KEYUP )
      return;
    base.WndProc (ref m);
  }
}

[Visual Basic]

Imports System.Windows.Forms

Public Class ComboBoxWithNoKeyUp
  Inherits ComboBox

  Private Const WM_KEYUP As Integer = &H101

  Protected Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_KEYUP Then
      Return
    End If
    MyBase.WndProc(m)
  End Sub
End Class

Contributed from George Shepherd's Windows Forms FAQ



Page view counter