winform textbox文本框設置多行輸入小技巧總結

對於我們經常要對文本框進行多行輸入後進行查詢、插入、刪除、更新操作等,要很方便的從其他諸如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"這樣子的格式。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章