winform textbox文本框设置多行输入小技巧总结

来源:互联网 发布:米思米 矩阵 编辑:程序博客网 时间:2024/05/23 01:11

对于我们经常要对文本框进行多行输入后进行查询、插入、删除、更新操作等,要很方便的从其他诸如Excel中进行复制粘贴的数据来说,textbox文本框必须设置

为多行属性:Multiline 属性设置为True,其次对字符串进行一下处理:

string Ocno=this.txt_OCNO.Text.Trim();            string strValue = this.txt_Barcode.Text;//设置文本框的内容            string shopNoValue = this.CB_ShopNo.Text;            if (Ocno == "" && strValue == "" && CB_ShopNo.Text == "")            {                MessageBox.Show("批次、条码、车间不能同时为空,至少要输入一个", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);            }            else            {                string[] arrValue = strValue.Split('\r');//将文本框的内容按回车进行分组                string strBarcodeList = "";//设置一个字符串接受分割开的每一个字符                DateTime DT_Start = Convert.ToDateTime(this.DTP_Start.Text);                DateTime DT_end = Convert.ToDateTime(this.DTP_End.Text);                for (int i = 0; i < arrValue.Length; i++)                {                    strBarcodeList = strBarcodeList + "'" + arrValue[i].Replace("\n", "") + "',";//将分隔开的字符串进行重新组装中间加,逗号                }                if (strBarcodeList.Length > 0)                    //strBarcodeList = strBarcodeList.Replace("\r","");//撤除将字符串最后的回车符                    strBarcodeList = strBarcodeList.Remove(strBarcodeList.Length - 1);//去除字符串最后的逗号
以上方便将字符串转换为:"A,B,C"这样子的格式。



原创粉丝点击