字符串連接應該做的事用&代替+。另外,刪除environment.newline以擺脫換行符。
textbox1.Text = "OS = " & combobox1.SelectedItem & " " &
combobox2.SelectedItem & " " & combobox3.SelectedItem
如果我誤解了問題,你要避免換行那裏是沒有價值的,你會做到以下幾點:
Dim strResult As String = "OS = " & Environment.NewLine
ComboBox1.SelectedIndex = 1
If ComboBox1.SelectedItem IsNot Nothing Then
strResult += ComboBox1.SelectedItem.ToString() & Environment.NewLine
End If
If ComboBox2.SelectedItem IsNot Nothing Then
strResult += ComboBox1.SelectedItem.ToString() & Environment.NewLine
End If
If ComboBox3.SelectedItem IsNot Nothing Then
strResult += ComboBox1.SelectedItem.ToString() & Environment.NewLine
End If
TextBox1.Text = strResult
檢查在添加到字符串之前,combobox是否具有SelectedItem。顯示如何將項目添加到組合框 – Fabio
編寫代碼以檢查哪些控件已選擇項目 – Plutonix