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

📄 form1.cs

📁 通过手机蓝牙控制个人电脑上的幻灯片的播放
💻 CS
字号:
#region Using directives
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
#endregion

namespace DevTestApp
{
    /// <summary>
    /// Summary description for form.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private MenuItem menuItem1;
        private MenuItem menuItem2;
        private MenuItem menuItem3;
        /// <summary>
        /// Main menu for the form.
        /// </summary>
        private System.Windows.Forms.MainMenu mainMenu1;
        private Label label1;
        private Label label2;
        private CheckBox chkSend;
        private TextBox textBox1;
        private MenuItem menuItem4;
        private ComboBox cbDevice;
        private ComboBox comboBox1;
        private MenuItem menuItem5;
        private MenuItem menuItem6;
        private MenuItem menuItem7;
        private MenuItem menuItem8;
        private MenuItem menuItem9;
        BTHWrapper.BTHConnector _connector;
        public Form1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem5 = new System.Windows.Forms.MenuItem();
            this.menuItem6 = new System.Windows.Forms.MenuItem();
            this.menuItem7 = new System.Windows.Forms.MenuItem();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.chkSend = new System.Windows.Forms.CheckBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.cbDevice = new System.Windows.Forms.ComboBox();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.Add(this.menuItem1);
            this.mainMenu1.MenuItems.Add(this.menuItem2);
            // 
            // menuItem1
            // 
            this.menuItem1.Text = "OK";
            this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
            // 
            // menuItem2
            // 
            this.menuItem2.MenuItems.Add(this.menuItem3);
            this.menuItem2.MenuItems.Add(this.menuItem4);
            this.menuItem2.MenuItems.Add(this.menuItem5);
            this.menuItem2.MenuItems.Add(this.menuItem6);
            this.menuItem2.MenuItems.Add(this.menuItem7);
            this.menuItem2.MenuItems.Add(this.menuItem8);
            this.menuItem2.MenuItems.Add(this.menuItem9);
            this.menuItem2.Text = "Menu";
            this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
            // 
            // menuItem3
            // 
            this.menuItem3.Text = "Connect";
            this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
            // 
            // menuItem4
            // 
            this.menuItem4.Text = "Search";
            this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
            // 
            // menuItem5
            // 
            this.menuItem5.Text = "Load";
            this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
            // 
            // menuItem6
            // 
            this.menuItem6.Text = "Directory";
            this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
            // 
            // menuItem7
            // 
            this.menuItem7.Text = "Test1";
            this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
            // 
            // menuItem8
            // 
            this.menuItem8.Text = "Test2";
            this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Nina", 8F, System.Drawing.FontStyle.Bold);
            this.label1.Location = new System.Drawing.Point(0, 0);
            this.label1.Size = new System.Drawing.Size(237, 15);
            // 
            // label2
            // 
            this.label2.Font = new System.Drawing.Font("Nina", 8F, System.Drawing.FontStyle.Bold);
            this.label2.Location = new System.Drawing.Point(0, 37);
            this.label2.Size = new System.Drawing.Size(237, 15);
            // 
            // chkSend
            // 
            this.chkSend.Location = new System.Drawing.Point(0, 98);
            this.chkSend.Size = new System.Drawing.Size(152, 22);
            this.chkSend.Text = "send";
            this.chkSend.CheckStateChanged += new System.EventHandler(this.chkSend_CheckStateChanged);
            // 
            // textBox1
            // 
            this.textBox1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
            this.textBox1.Location = new System.Drawing.Point(0, 55);
            this.textBox1.Multiline = true;
            this.textBox1.Size = new System.Drawing.Size(237, 46);
            this.textBox1.Text = "text";
            // 
            // cbDevice
            // 
            this.cbDevice.Location = new System.Drawing.Point(0, 126);
            this.cbDevice.Size = new System.Drawing.Size(240, 24);
            this.cbDevice.SelectedIndexChanged += new System.EventHandler(this.cbDevice_SelectedIndexChanged);
            // 
            // comboBox1
            // 
            this.comboBox1.Location = new System.Drawing.Point(0, 153);
            this.comboBox1.Size = new System.Drawing.Size(240, 24);
            // 
            // menuItem9
            // 
            this.menuItem9.Text = "Preview";
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(176, 180);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.chkSend);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.cbDevice);
            this.Controls.Add(this.comboBox1);
            this.Menu = this.mainMenu1;
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);

        }

        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private ArrayList SearchedDeviceList;
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            //label1.Text = 
           // _connector.Connect(cbDevice.SelectedValue.ToString());
            _connector.Connect("00:03:C9:2B:9D:98");

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            _connector = new BTHWrapper.BTHConnector();
            //_connector.InitialiseBluetooth();
            //_connector.InitialiseWinsock();
            label1.Text += _connector.InitialiseSocket();
        }



        private void chkSend_CheckStateChanged(object sender, EventArgs e)
        {
            label1.Text = "";
            _connector.SendMessage(textBox1.Text);
            string str = _connector.RecvMessage();
            textBox1.Text = Convert.ToString(str.Length);
            byte[] testbyte = Convert.FromBase64String(str);
            for (int i = 0; i < testbyte.GetLength(0); i++)
            {
                label1.Text += Convert.ToString(Convert.ToInt32(testbyte[i])) + " ";
            }

            label2.Text = System.Text.Encoding.Unicode.GetString(testbyte,0,testbyte.GetLength(0));
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            
            ArrayList al = new ArrayList(_connector.FindDevice());

            if (al.Count > 0)
            {
                //XMLControl.WriteDeviceList();  
                XMLControl.WriteDeviceList(al, "\\Storage\\device.xml");

                ArrayList devlst = new ArrayList();
                devlst = XMLControl.ReadDeviceList("\\Storage\\device.xml");


                cbDevice.DataSource = devlst;

                cbDevice.DisplayMember = "DeviceName";
                cbDevice.ValueMember = "Address";
                cbDevice.SelectedIndex = 0;
            }
            else
            {
                
            }
        }


        private void cbDevice_SelectedIndexChanged(object sender, EventArgs e)
        {
            //MessageBox.Show(comboBox.Items.Count.ToString());
            //MessageBox.Show(cbDevice.SelectedValue.ToString());
            //textBox1.Text = cbDevice.SelectedValue.ToString();
        }

        private void menuItem5_Click(object sender, EventArgs e)
        {
            ArrayList devlst = new ArrayList();
            devlst = XMLControl.ReadDeviceList("\\Storage\\device.xml");
            cbDevice.DataSource = devlst;

            cbDevice.DisplayMember = "DeviceName";
            cbDevice.ValueMember = "Address";
            cbDevice.SelectedIndex = 0;
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {

        }

        private void menuItem6_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2(_connector);
            f.Show();
        }

        private void menuItem7_Click(object sender, EventArgs e)
        {
            
            string stt = "DIRECT:document";
            _connector.SendMessage("DIRECT:document");
            this.label2.Text = Convert.ToString(stt.Length);
            string sttt = _connector.RecvMessage();
            
            this.textBox1.Text = sttt;
        }

        private void menuItem8_Click(object sender, EventArgs e)
        {
            _connector.SendMessage("DIRECT:document");
            this.textBox1.Text = "";
            this.textBox1.Text = _connector.RecvMessage();
        }
    }
}

⌨️ 快捷键说明

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