⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.vb

📁 利用vb.net来接收来自其他窗体创送的消息。
💻 VB
字号:
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
'说明:vb中接收消息的窗体的text属性,必须设置成和配置文件PubSunionSet.ini中的一致。
Public Class test1
    Inherits System.Windows.Forms.Form
    Private textBox1 As System.Windows.Forms.TextBox
    Public strInfo As String
    'Private components As System.ComponentModel.Container = Nothing
    Private Const WM_COPYDATA As Integer = 74

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.textBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'textBox1
        '
        Me.textBox1.Location = New System.Drawing.Point(16, 88)
        Me.textBox1.Name = "textBox1"
        Me.textBox1.Size = New System.Drawing.Size(376, 21)
        Me.textBox1.TabIndex = 0
        Me.textBox1.Text = "test1"
        '
        'test1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(432, 266)
        Me.Controls.Add(Me.textBox1)
        Me.Name = "test1"
        Me.Text = "test1"
        Me.ResumeLayout(False)

    End Sub
    '<STAThread()> _
    '       Private Shared Sub Main()
    '    Application.Run(New Form1)
    'End Sub
    '接受窗体上的消息
    'strInfo为返回信息
    'Me.textBox1.Text用于测试
    Protected Overrides Sub DefWndProc(ByRef m As System.Windows.Forms.Message)
        Select Case (m.Msg)
            Case WM_COPYDATA
                Dim mystr As COPYDATASTRUCT = New COPYDATASTRUCT
                Dim mytype As Type = mystr.GetType
                mystr = CType(m.GetLParam(mytype), COPYDATASTRUCT)
                strInfo = mystr.lpData
                Me.textBox1.Text = strInfo
            Case Else
                MyBase.DefWndProc(m)
        End Select
    End Sub

    '定义消息的结构体
    <StructLayout(LayoutKind.Sequential)> _
    Public Structure COPYDATASTRUCT

        Public dwData As IntPtr

        Public cbData As Integer

        <MarshalAs(UnmanagedType.LPStr)> _
        Public lpData As String
    End Structure
#End Region

End Class


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -