using System; using System.Windows.Forms; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon { public partial class TextBoxGeneratePaCode : UserControl { public TextBoxGeneratePaCode() { InitializeComponent(); toolTip1.SetToolTip(GeneratePaCode, "自动生成箱号"); } //选中全部文本 public void SelectAll() { enterTextBox1.SelectAll(); } private bool showClickIcon; //重写Text方法,用于接收或者传递值 public override string Text { get { return enterTextBox1.Text; } set { enterTextBox1.Text = value; } } private string pr_id; public string Pr_id { get { return pr_id; } set { pr_id = value; } } private string MakeCode1; private string Caller1; private string ProdCode1; public string MakeCode { get { return MakeCode1; } set { MakeCode1 = value; } } public string Caller { get { return Caller1; } set { Caller1 = value; } } public string ProdCode { get { return ProdCode1; } set { ProdCode1 = value; } } public bool ShowClickIcon { get { return showClickIcon; } set { showClickIcon = value; } } public void GeneratePaCode_Click(object sender, EventArgs e) { IconClick?.Invoke(sender, new EventArgs()); //如果未实现则继续 try { enterTextBox1.Text = LogicHandler.GetOutBoxCode(Caller1, MakeCode1, ProdCode1, Entity.User.UserLineCode); } catch (Exception) { LogManager.DoLog("请先获取产品编号和工单号"); } } //定义委托 public delegate void OnTextChange(object sender, EventArgs e); //定义事件 public event OnTextChange UserControlTextChanged; public event OnTextChange IconClick; private void enterTextBox1_TextChanged(object sender, EventArgs e) { UserControlTextChanged?.Invoke(sender, new EventArgs()); } private void enterTextBox1_KeyDown(object sender, KeyEventArgs e) { base.OnKeyDown(e); } private void TextBoxGeneratePaCode_SizeChanged(object sender, EventArgs e) { enterTextBox1.Width = Width - GeneratePaCode.Width - 3; } private void TextBoxGeneratePaCode_Load(object sender, EventArgs e) { if (!showClickIcon) { GeneratePaCode.Visible = false; } } } }