在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → C# 短信猫 软件源码下载

C# 短信猫 软件源码下载

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:0.20M
  • 下载次数:51
  • 浏览次数:454
  • 发布时间:2016-04-07
  • 实例类别:Windows系统编程
  • 发 布 人:handiyar
  • 文件格式:.rar
  • 所需积分:5
 相关标签: 短信 C# 短信猫

实例介绍

【实例简介】

【实例截图】

【核心代码】


using System;
using System.Drawing;
using System.IO.Ports;
using System.Windows.Forms;
using GSMMODEM;
 
namespace 短信猫
{
    public partial class Form1 : Form
    {
        private GSMModem gm = new GSMModem();

        //委托 收到短信的回调函数委托
        delegate void UpdataDelegate();         //可以有参数,本处不需要
        UpdataDelegate UpdateHandle = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //初始化控件
            foreach (string s in SerialPort.GetPortNames())
            {
                comboBox1.Items.Add(s);
            }
            if (comboBox1.Items.Count == 0)
            {
                label3.Text = "未检测到串口";
                label3.ForeColor = Color.Red;
            }
            else
            {
                comboBox1.SelectedIndex = 0;
            }
            comboBox2.SelectedIndex = 0;

            //初始化设备类对象 gm
            if (comboBox1.Items.Count == 0)
            {

            }
            else
            {
                gm.ComPort = comboBox1.SelectedItem.ToString();
            }
            gm.BaudRate = Convert.ToInt32(comboBox2.SelectedItem);

            gm.OnRecieved  = new GSMModem.OnRecievedHandler(gm_OnRecieved);

            UpdateHandle = new UpdataDelegate(UpdateLabel8);        //实例化委托

        }

        void gm_OnRecieved(object sender, EventArgs e)
        {
            Invoke(UpdateHandle, null);
        }

        void UpdateLabel8()
        {
            label8.Text = "有新消息";
            label8.ForeColor = Color.Green;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gm.IsOpen)
            {
                label3.Text = "更改无效";
                label3.ForeColor = Color.Red;
            }
            else
            {
                gm.ComPort = comboBox1.SelectedItem.ToString();
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            gm.BaudRate = Convert.ToInt32(comboBox2.SelectedItem);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (gm.IsOpen == false)
            {
                try
                {
                    gm.Open();
                    label3.Text = "连接成功";
                    label3.ForeColor = Color.Green;
                }
                catch
                {
                    label3.Text = "连接失败";
                    label3.ForeColor = Color.Red;
                }
            }
            else
            {
                label3.Text = "已连接";
                label3.ForeColor = Color.Green;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(gm.IsOpen)
            {
                try
                {
                    gm.Close();
                    label3.Text = "断开成功";
                    label3.ForeColor = Color.Red;
                }
                catch
                {
                    label3.Text="断开失败";
                    label3.ForeColor=Color.Red;
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //短信过长,通知用户字数 直接返回
            if (textBox2.Text.Length > 70)
            {
                label6.Text = "短信"   textBox2.Text.Length.ToString()   "字";
                label6.ForeColor = Color.Red;
                return;
            }
            if (gm.IsOpen)
            {
                try
                {
                    gm.SendMsg(textBox1.Text, textBox2.Text);
                }
                catch
                {
                    label6.Text = "发送失败";
                    label6.ForeColor = Color.Red;
                    return;
                }
                label6.Text = "发送成功";
                label6.ForeColor = Color.Green;
            }
            else
            {
                label6.Text = "设备未连接";
                label6.ForeColor = Color.Red;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox4.Text = null;

            string msgCenter, phone, msg, time;
            if (gm.IsOpen)
            {
                try
                {
                    gm.ReadMsgByIndex(Convert.ToInt32(textBox3.Text), out msgCenter, out phone, out msg, out time);
                    textBox4.Text = "短信中心:"   msgCenter   "\r\n"   "手机号码:"   phone   "\r\n"  
                            "短信内容:"   msg   "\r\n"   "发送时间:"   time.Substring(0, 4)   "-"  
                            time.Substring(4, 2)   "-"   time.Substring(6, 2)   " "   time.Substring(8, 2)  
                            ":"   time.Substring(10, 2)   ":"   time.Substring(12, 2);
                    label9.Text = "读取成功";
                    label9.ForeColor = Color.Green;
                }
                catch
                {
                    label9.Text = "读取失败";
                    label9.ForeColor = Color.Red;
                    return;
                }
            }
            else
            {
                label9.Text = "设备未连接";
                label9.ForeColor = Color.Red;
            }

        }

        private void button5_Click(object sender, EventArgs e)
        {
            //
            textBox5.Text = null;

            if (label8.Text != "有新消息")
            {
                label8.Text = "没有新消息";
                label8.ForeColor = Color.Red;
                return;
            }

            string msgCenter, phone, msg, time;
            if (gm.IsOpen)
            {
                try
                {
                    gm.ReadMsgByIndex(gm.NewMsgIndex, out msgCenter, out phone, out msg, out time);
                    textBox5.Text = "短信中心:"   msgCenter   "\r\n"   "手机号码:"   phone   "\r\n"  
                            "短信内容:"   msg   "\r\n"   "发送时间:"   time.Substring(0, 4)   "-"  
                            time.Substring(4, 2)   "-"   time.Substring(6, 2)   " "   time.Substring(8, 2)  
                            ":"   time.Substring(10, 2)   ":"   time.Substring(12, 2);
                    label8.Text = "读取成功";
                    label8.ForeColor = Color.Green;
                }
                catch
                {
                    label8.Text = "读取失败";
                    label8.ForeColor = Color.Red;
                    return;
                }
            }
            else
            {
                label8.Text = "设备未连接";
                label8.ForeColor = Color.Red;
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (gm.IsOpen)
            {
                try
                {
                    gm.DeleteMsgByIndex(Convert.ToInt32(textBox3.Text));
                }
                catch
                {
                    label9.Text = "删除失败";
                    label9.ForeColor = Color.Red;
                    return;
                }
            }
            else
            {
                label9.Text = "设备未连接";
                label9.ForeColor = Color.Red;
                return;
            }
            label9.Text = "删除成功";
            label9.ForeColor = Color.Green;
        }
    }
}


标签: 短信 C# 短信猫

实例下载地址

C# 短信猫 软件源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警