Public Class Form1 Private WithEvents win As Window Dim yosoku As List(Of String) Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load win = New Window() win.AssignHandle(TextBox1.Handle) End Sub Private Sub win_Typing(ByVal text As String) Handles win.Typing TextBox1.Text = text If yosoku Is Nothing Then ReadFile() End If Dim yosoku_No As String = TextBox1.Text ListBox1.Items.Clear() For i As Integer = 0 To yosoku.Count - 1 If yosoku_No = yosoku(i).Substring(0, Math.Min(yosoku_No.Length, yosoku(i).Length)) Then ListBox1.Items.Add(yosoku(i).Substring(yosoku(i).IndexOf(",") + 1)) End If Next End Sub Sub ReadFile() yosoku = New List(Of String)() Dim yosokuFileName = Path.Combine(Application.StartupPath, "yosoku.txt") Dim fs As FileStream = New FileStream(yosokuFileName, FileMode.Open) Dim sr As StreamReader = New StreamReader(fs, Encoding.GetEncoding("shift_jis")) Dim Buffer As String Buffer = sr.ReadLine() Do Until Buffer Is Nothing yosoku.Add(Buffer) Buffer = sr.ReadLine() Loop sr.Close() End Sub Private Class Window Inherits NativeWindow 'ウィンドウ クラスの作成と登録を自動的に管理 Public Event Typing(ByVal text As String) Private Declare Function ImmGetContext Lib "imm32" _ (ByVal hWnd As IntPtr) As IntPtr '指定ウィンドウのコンテキストハンドルを取得する Private Declare Auto Function ImmGetCompositionString Lib "imm32" _ (ByVal hIMC As IntPtr, ByVal dwIndex As Integer, ByVal lpBuf As System.Text.StringBuilder, _ ByVal dwBufLen As Integer) As Integer '変換文字列を取得する Private Declare Function ImmReleaseContext Lib "imm32.dll" _ (ByVal hWnd As IntPtr, ByVal hIMC As IntPtr) As Integer 'ImmGetContextで取得したハンドルを解放する Protected Overrides Sub WndProc(ByRef m As Message) Const WM_IME_COMPOSITION As Integer = &H10F '変換が実行されたことを受信する(フラグはGCS_xxxxx) Const GCS_COMPSTR As Integer = 8 If m.Msg = WM_IME_COMPOSITION Then If (m.LParam.ToInt32() And GCS_COMPSTR) <> 0 Then Dim imc As IntPtr = ImmGetContext(Handle) Dim length As Integer = ImmGetCompositionString(imc, GCS_COMPSTR, Nothing, 0) Dim buf As New System.Text.StringBuilder(length) Dim l As Integer = ImmGetCompositionString(imc, GCS_COMPSTR, buf, length) ImmReleaseContext(Handle, imc) RaiseEvent Typing(buf.ToString(0, l \ 2)) End If End If MyBase.WndProc(m) End Sub End Class