form1.cs

来自「运用了Windows自身带有的服务(Messages),通过打开此服务而发送相关」· CS 代码 · 共 53 行

CS
53
字号
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;


namespace 实现通讯信使
{
    public partial class Form1 : Form
    {
        [DllImport("Netapi32", CharSet = CharSet.Unicode)]
        public static extern int NetMessageBufferSend(
         string servername, //服务器名称,为NULL
         string fromname, //接收方名称,可为IP或计算机名称
         string msgname, //信息名称,为NULL
         string buf, //信息
         int buflen); //信息长度
        public Form1()
        {
            InitializeComponent();
        }

        private void but_send_Click(object sender, EventArgs e)
        {
            try
            {
                this.timer1.Enabled = true;
                byte[] bBuffer = System.Text.Encoding.Unicode.GetBytes(txt_Details.Text);
                int nRet = NetMessageBufferSend(null, txt_server.Text, null, txt_Details.Text, txt_Details.Text.Length * 2 + 2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            but_send_Click(sender,e);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = false ;
        }

       
     
    }
}

⌨️ 快捷键说明

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