您的位置:首页 > 编程语言 > C#

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

2013-06-24 10:02 344 查看
对于我们经常要对文本框进行多行输入后进行查询、插入、删除、更新操作等,要很方便的从其他诸如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"这样子的格式。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# winform textbox