Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 两个解决方案之间的vb.net按键事件(visual studio 2010)_C#_Vb.net_Winforms_Visual Studio 2010 - Fatal编程技术网

C# 两个解决方案之间的vb.net按键事件(visual studio 2010)

C# 两个解决方案之间的vb.net按键事件(visual studio 2010),c#,vb.net,winforms,visual-studio-2010,C#,Vb.net,Winforms,Visual Studio 2010,我是Vb新手,请指导我以下事项: 不同溶液有两种不同的形式(例如:SolutionA\Form1和SolutionB\Form2) 两个表单都有多个文本框 首先,我们在SolutionA\Form1中的文本框中输入数据。然后,通过使用按键事件,光标移动到SolutionB\Form2中的文本框 之后,通过使用SolutionB\Form2中的按键事件,光标移回SolutionA\Form1中的另一个文本框 可以这样点吗?如果可能,请让我知道如何进行编码。我正在使用VisualStudio2010

我是Vb新手,请指导我以下事项:

不同溶液有两种不同的形式(例如:SolutionA\Form1和SolutionB\Form2)

两个表单都有多个文本框

首先,我们在SolutionA\Form1中的文本框中输入数据。然后,通过使用按键事件,光标移动到SolutionB\Form2中的文本框

之后,通过使用SolutionB\Form2中的按键事件,光标移回SolutionA\Form1中的另一个文本框

可以这样点吗?如果可能,请让我知道如何进行编码。我正在使用VisualStudio2010。谢谢


我创建了一个测试表单(表单1),其中有一个名为txtPart的文本框

一旦我点击“回车”按钮,我想把txtPart中的数据传输到记事本。 我如何从这里调用类NotePadSend和Receive

Public Class Form1

    Private Sub txtPart_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPart.KeyPress

        Try
            If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
                ' How to call NotepadSendAndReceive class here?
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub

End Class
请帮忙。多谢各位

================================================================================

我创建了一个测试表单(表单1),其中有一个名为txtPart的文本框

一旦我点击“回车”按钮,我想把txtPart中的数据传输到记事本。我如何从这里调用类NotePadSend和Receive? 公开课表格1

Private Sub txtPart_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPart.KeyPress

    Try
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
            ' How to call NotepadSendAndReceive class here?
        End If
    Catch ex As Exception
        MessageBox.Show(ex.ToString)
    End Try
End Sub
末级


请帮忙。谢谢。

这可以通过使用NamedPipeServer(高复杂性)或 否则,请使用WinApi(我建议这样做)

看看这个:

Public Class NotepadSendAndReceive
        Public Const VK_RETURN As UInteger = &HD
        Public Const WM_SETFOCUS As UInteger = &H7
        Public Const WM_KILLFOCUS As UInteger = &H8
        Public Const WM_CHAR As UInteger = &H102
        Public Const WM_SETTEXT As UInteger = &HC
        Public Const WM_KEYDOWN As UInteger = &H100
        Public Const WM_KEYUP As UInteger = &H101
        Public Const cap As Integer = 1048576
        Public Const WM_CLICK As UInteger = &HF5
        Public Const WM_GETTEXT As UInteger = &HD
        Public Const WM_GETTEXTLENGTH As UInteger = &HE

        <DllImport("User32.Dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowTextLength(hWnd As IntPtr) As Integer
        End Function
        <DllImport("User32.Dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Shared Function GetWindowText(hWnd As IntPtr, lpString As StringBuilder, nMaxCount As Integer) As Integer
        End Function
        <DllImport("User32.Dll")> Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInt32, wParam As IntPtr, lParam As String) As IntPtr
        End Function
        <DllImport("User32.Dll")> Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As Integer, lParam As StringBuilder) As Integer
        End Function
        <DllImport("User32.Dll")> Public Shared Function PostMessage(hWnd As Integer, msg As UInteger, wParam As UInteger, lParam As Integer) As IntPtr
        End Function
        <DllImport("User32.Dll")> Public Shared Function PostMessage(hWnd As Integer, msg As UInteger, wParam As UInteger, lParam As UInteger) As IntPtr
        End Function
        <DllImport("User32.Dll")> Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
        End Function
        <DllImport("User32.Dll")> Private Shared Function FindWindowEx(parentHandle As IntPtr, childAfter As IntPtr, className As String, windowTitle As IntPtr) As IntPtr
        End Function

        Private Shared Function GetStringOfEditor() As String
            Return GetText(GetProcNumber("Editor"))
        End Function

        Public Shared Sub SendStringToEditor(T As String)
            SendMessage(GetProcNumber("Editor"), &HC, CType(cap, IntPtr), T)
        End Sub

        Public Shared Sub SendEnter(Hwndd As IntPtr)
            SendMessage(Hwndd, WM_SETFOCUS, CType(cap, IntPtr), String.Empty)
            Threading.Thread.Sleep(10)
            PostMessage(Hwndd.ToInt32(), WM_KEYDOWN, &HD, &H1C0001)
            PostMessage(Hwndd.ToInt32(), WM_CHAR, &HD, &H1C0001)
            Threading.Thread.Sleep(10)
            PostMessage(Hwndd.ToInt32(), WM_KEYUP, &HD, &HC01C0001UI)
            SendMessage(Hwndd, WM_KILLFOCUS, CType(cap, IntPtr), String.Empty)
        End Sub

        Private Shared Function GetProcNumber(pTitle As String) As IntPtr
            Dim Pzs As New List(Of String)
            For Each p As Process In Process.GetProcesses
                If p.MainWindowTitle.Contains(pTitle) Then Pzs.Add(p.MainWindowTitle)
            Next
            If Pzs.Count > 0 Then Return FindWindowEx(FindWindow("Notepad", Pzs(0)), IntPtr.Zero, "Edit", IntPtr.Zero)
        End Function

        Private Shared Function GetText(hWnd As IntPtr) As String
            Dim nLen As Integer = CInt(SendMessage(hWnd, WM_GETTEXTLENGTH, IntPtr.Zero, String.Empty))
            Dim pText As New StringBuilder(nLen + 1)
            SendMessage(hWnd, WM_GETTEXT, nLen + 1, pText)
            Return pText.ToString()
        End Function

    End Class
你只需要定制一下,你只需要 查找文本框的当前句柄

看看:

  If Pzs.Count > 0 Then Return FindWindowEx(FindWindow("Notepad", Pzs(0)), IntPtr.Zero, "Edit", IntPtr.Zero)
程序使用“FindWindowEx”查找“Notepad”的当前句柄,然后查找“Edit”元素的子句柄

然后,您就拥有了记事本编辑区域的正确当前句柄,例如,您可以向其发送文本

在您的情况下,它将是“Form2”,然后您必须知道文本框的名称(这可以通过使用WinSpy++找到)


问候。

您的按键事件中是否有
Form2.TextBox1.Focus()
?没有,因为我不知道如何将Focus()放入不同的解决方案中。不过,如果两种形式都是同一种解决方案,我总是用这种方法。谢谢。谢谢SiriSch先生!我将研究这种方法并尝试进行编码。我在很多论坛上搜索过,但从来没有找到过这个想法。再次感谢:)
  If Pzs.Count > 0 Then Return FindWindowEx(FindWindow("Notepad", Pzs(0)), IntPtr.Zero, "Edit", IntPtr.Zero)