📄 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 ZylGPSReceiverMobile;
namespace CSharpDemo
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
// This delegate enables asynchronous calls for setting
// the text property on a TextBox control.
private delegate void SetTextCallback(string text);
private delegate void RefreshPaintBoxCallBack();
private void Set_textBoxOut(string text)
{
try
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
this.Invoke(new SetTextCallback(Set_textBoxOut),
new object[] { text });
return;
}
if (this.textBoxOut.Text.Length > 10000)
textBoxOut.Text = String.Empty;
this.textBoxOut.Text += text;
this.textBoxOut.SelectionStart = textBoxOut.Text.Length;
this.textBoxOut.SelectionLength = 0;
this.textBoxOut.ScrollToCaret();
}
catch
{
this.textBoxOut.Text = string.Empty;
}
}
private void Set_textBoxCoord(string text)
{
try
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
this.Invoke(new SetTextCallback(Set_textBoxCoord),
new object[] { text });
return;
}
this.textBoxCoord.Text = text;
}
catch { }
}
private void Set_textBoxParams(string text)
{
try
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
this.Invoke(new SetTextCallback(Set_textBoxParams),
new object[] { text });
return;
}
this.textBoxParams.Text = text;
}
catch { }
}
private void RefreshPaintBox()
{
try
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.InvokeRequired)
{
this.Invoke(new RefreshPaintBoxCallBack(RefreshPaintBox));
return;
}
this.pBox.Refresh();
}
catch { }
}
private void btnClose_Click(object sender, EventArgs e)
{
cmpGpsReceiver.Close();
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (lstPorts.SelectedIndex >= 0 && lstBaud.SelectedIndex >= 0)
{
cmpGpsReceiver.Port = (SerialCommPort)(lstPorts.SelectedIndex + 1);
cmpGpsReceiver.BaudRate = (SerialBaudRate)(Convert.ToUInt32(lstBaud.SelectedItem.ToString()));
if (!cmpGpsReceiver.Open())
MessageBox.Show("Cannot open.");
}
else
{
MessageBox.Show("Select port and baud rate.");
}
}
private void cmpGpsReceiver_Received(object sender, ZylGPSReceiverMobile.DataEventArgs e)
{
string str;
str = "Lt: " + cmpGpsReceiver.Position.Latitude_Degree.ToString() + "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -