Hi Chris,
I am not familiay with C, so I used a tool to convert C to VB.net. Her is
the result:
Code of the form:
'
' Author: Sergey Bogdanov <
[email protected]>
' Url:
http://www.sergeybogdanov.com
'
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports OpenNETCF.Windows.Forms
Namespace Test
'/ <summary>
'/ Summary description for Form1.
'/ </summary>
Public Class Form1
Inherits Form
Private textBox1 As TextBoxFiltered
Private mainMenu1 As MainMenu
Public Sub New()
'
' Required for Windows Form Designer support
'
InitializeComponent()
Me.textBox1 = New TextBoxFiltered()
Me.textBox1.Location = New Point(28, 28)
Me.textBox1.Multiline = True
Me.textBox1.Size = New Size(144, 120)
Me.Controls.Add(textBox1)
Dim i As Integer
For i = 0 To 29
textBox1.Text += "The quick brown fox jumped over the lazy dog. "
Next i
ApplicationEx.AddMessageFilter(textBox1)
End Sub 'New
'/ <summary>
'/ Clean up any resources being used.
'/ </summary>
Protected Overrides Sub Dispose(disposing As Boolean)
MyBase.Dispose(disposing)
End Sub 'Dispose
#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 Sub InitializeComponent()
Me.mainMenu1 = New System.Windows.Forms.MainMenu()
'
' Form1
'
Me.ClientSize = New System.Drawing.Size(190, 183)
Me.MaximizeBox = False
Me.Menu = Me.mainMenu1
Me.MinimizeBox = False
Me.Text = "Form1"
End Sub 'InitializeComponent
#End Region
'/ <summary>
'/ The main entry point for the application.
'/ </summary>
Shared Sub Main()
ApplicationEx.Run(New Form1())
End Sub 'Main
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub 'Form1_Load
Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles
MyBase.Closed
ApplicationEx.RemoveMessageFilter(textBox1)
End Sub 'Form1_Closed
End Class 'Form1
End Namespace 'Test
The line: <Protected Overrides Sub Dispose(disposing As Boolean) > seems to
be problematic1
Code of TextboxEx.vb:
Imports System
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Imports OpenNETCF.Windows.Forms
Imports System.Runtime.InteropServices
Namespace Test
Class TextBoxFiltered
Inherits TextBox
Implements IMessageFilter 'ToDo: Add Implements Clauses for
implementation methods of these interface(s)
Private _hwnd As IntPtr
Public Sub New()
End Sub 'New
Protected Overrides Sub OnParentChanged(e As EventArgs)
'gets control's window handle
Me.Capture = True
_hwnd = GetCapture()
Me.Capture = False
MyBase.OnParentChanged(e)
End Sub 'OnParentChanged
#Region "IMessageFilter Members"
Public Function PreFilterMessage(ByRef m As Message) As Boolean
If m.HWnd = _hwnd Then
Return MsgHandler(m)
End If
Return False
End Function 'PreFilterMessage
#End Region
Private Function MsgHandler(m As Message) As Boolean
If m.Msg = WM_KEYDOWN Then
Dim k As Keys = CType(m.WParam.ToInt32(), Keys)
Select Case k
Case Keys.Up, Keys.Down
Return True
End Select
End If
Return False
End Function 'MsgHandler
Private Const WM_KEYDOWN As Integer = &H100
<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Class 'TextBoxFiltered
End Namespace 'Test
Would be fine if you could have a look at this.
Thanks a lot
Werner