📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using UtilControl;
namespace RemoteApp
{
public partial class Form1 : Form
{
BTH_Connection_Wrap.BTHWrapConnectior conn = new BTH_Connection_Wrap.BTHWrapConnectior();
private const int BTH_DISCONNECT = 0;
private const int BTH_READY = 1;
private const int BTH_CONNECT = 2;
KeyMapping.MappingControl map = new KeyMapping.MappingControl();
//bool IsClose = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Resize(object sender, System.EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
Hide();
}
private void appNotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
//Show();
WindowState = FormWindowState.Normal;
}
Thread threadFunc;
private void Form1_Load(object sender, EventArgs e)
{
threadFunc = new Thread(new ThreadStart(StartRemoteService));
threadFunc.Start();
Hide();
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void StartRemoteService()
{
while (true)
{
while(StartBluetooth())
{
while (WaitingForConnection())
{
StartRecviceData();
map.Command("SYS:DISCONNECT");
}
}
Thread.Sleep(5000);
}
}
private bool StartBluetooth()
{
appNotifyIcon.Icon = GetIcon(BTH_DISCONNECT);
if (conn.Start() && conn.RegisterBlueToothService())
{
this.textBox1.Text += "Start Bluetooth Success\r\n";
return true;
}
else
{
this.textBox1.Text += "Start Bluetooth Failed\r\n";
return false;
}
}
public bool WaitingForConnection()
{
bool IsListeningSuccess = false;
appNotifyIcon.Icon = GetIcon(BTH_READY);
IsListeningSuccess = conn.ListenConnection();
if (IsListeningSuccess)
{
this.textBox1.Text += "Start Listening Success\r\n";
}
else
{
this.textBox1.Text += "Start Listening Failed \r\n";
return false;
}
conn.AcceptConnection();
this.textBox1.Text += "Connection Estiblished \r\n";
return IsListeningSuccess;
}
public void StartRecviceData()
{
appNotifyIcon.Icon = GetIcon(BTH_CONNECT);
int i = 0;
int count = 0;
while (true)
{
string str = conn.RecieveMessage();
this.textBox1.Text = Convert.ToString(count++) + ". ";
this.textBox1.Text += "Recv length" + Convert.ToString(str.Length) + "\r\n";
this.textBox1.Text += str + "\r\n";
if (str.Length == 0)
{
i++;
if (i == 2)
{ break;}
}
else
{ i = 0;}
if (conn.IsDisconnected())
{ break;}
if (str.Equals("term"))
{
conn.Send("term"); ;
}
if (str.Equals("PIC"))
{
Thread.Sleep(200);
conn.SendData(CaptureScreen.CaptureScreen.GetDesktopImage());
}
else
{
string strRtn = map.Command(str);
//string strRtn = "done";
if (!strRtn.Equals("done"))
{
Thread.Sleep(500);
this.textBox1.Text += "Send length" + Convert.ToString(strRtn.Length) + "\r\n";
this.textBox1.Text += strRtn + "\r\n";
conn.SendMessage(strRtn);
}
}
}
}
public void HandShaking()
{
}
private void btnStop_Click(object sender, EventArgs e)
{
conn.Close();
threadFunc.Abort();
//this.Dispose();
Application.Exit();
}
private Icon GetIcon(int BluetoothState)
{
Icon _StateIcon;
switch (BluetoothState)
{
case BTH_DISCONNECT:
_StateIcon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());
break;
case BTH_READY:
_StateIcon = Icon.FromHandle(((Bitmap)imageList1.Images[1]).GetHicon());
break;
case BTH_CONNECT:
_StateIcon = Icon.FromHandle(((Bitmap)imageList1.Images[2]).GetHicon());
break;
default:
_StateIcon = null;
break;
}
return _StateIcon;
}
private void closeAppilcationToolStripMenuItem_Click(object sender, EventArgs e)
{
conn.Close();
threadFunc.Abort();
Application.Exit();
}
private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
{
// Show();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -