using ReaLTaiizor.Forms;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace LB_VisionControls.Forms
|
{
|
public partial class RenameForm : MaterialForm
|
{
|
// 定义一个委托和事件
|
public delegate void UpdateStringHandler(string oriString, string newString);
|
public event UpdateStringHandler UpdateStringEvent;
|
public bool bRename = false;
|
public string strOriName { get; set; }
|
public string strNewName { get; set; }
|
|
public bool bCheckBan = true;
|
|
public RenameForm(string strOrigin = "", bool bCheckBan = true)
|
{
|
InitializeComponent();
|
// 禁止修改窗口大小
|
this.FormBorderStyle = FormBorderStyle.FixedDialog;
|
this.uiTextBox1.Text = strOrigin;
|
this.uiTextBox2.Text = strOrigin;
|
this.bCheckBan = bCheckBan;
|
}
|
|
List<string> banStr = new List<string>() { ",", ".", "\\", "/", ":", "*", "?", "\"", "<", ">", "|", "\0" };
|
|
private void uiButtonRename_Click(object sender, EventArgs e)
|
{
|
if (string.IsNullOrEmpty(this.uiTextBox2.Text.Trim()))
|
{
|
MessageBox.Show("名称不允许为空", "异常");
|
return;
|
}
|
|
if (bCheckBan)
|
{
|
foreach (string str in banStr)
|
{
|
if (this.uiTextBox2.Text.Contains(str))
|
{
|
MessageBox.Show("名称不允许出现, . \\ / : * ? \" < > | 等字符", "异常");
|
return;
|
}
|
}
|
}
|
|
// 触发事件,通知父窗体更新string
|
UpdateStringEvent?.Invoke(this.uiTextBox1.Text, this.uiTextBox2.Text);
|
bRename = true;
|
strOriName = this.uiTextBox1.Text;
|
strNewName = this.uiTextBox2.Text;
|
this.Close();
|
}
|
|
private void uiButtonCancel_Click(object sender, EventArgs e)
|
{
|
this.Close();
|
}
|
}
|
}
|