判断字符串是否为空
if (LogFileSavePathText.Text.Trim() == String.Empty)
{
MessageBox.Show("Please select path which will be save sensor data!",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
判断文件夹是否存在
if (Directory.Exists(LogFileSavePathText.Text) == false)
{
MessageBox.Show("Please check if the Save Log Folder path exists", "Waring");
return;
}
判断数据是0x00~0xFF的正常字符
public bool IsHexadecimal(string str)
{
const string PATTERN = @"[A-Fa-f0-9]+$";
return System.Text.RegularExpressions.Regex.IsMatch(str, PATTERN);
}
if (WifiIDText.Text.Trim() == String.Empty)
{
MessageBox.Show("Please write the Wifi Device ID!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (IsHexadecimal(WifiIDText.Text.ToString()) == false)
{
MessageBox.Show("Please enter the correct hexadecimal format", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if(Convert.ToInt32(WifiIDText.Text, 16) > 255)
{
MessageBox.Show("The range of Device ID is 0x00~0xFF", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
对于TextBox的字符进行追加和换行显示
private void OutStatusLog(string str)
{
LogText.AppendText(str);
LogText.ScrollToCaret();
}