下面的示例使用派生类 TextBox 将所有文本字符串从多行文本框控件中提取出来,并使用 Debug.WriteLine 方法显示它们。此示例假定已创建一个名为 textBox1 的 TextBox 控件,并且此控件已包含一些文本行。[Visual Basic] Public Sub ViewMyTextBoxContents() Dim counter as Integer 'Create a string array and store the contents of the Lines property. Dim tempArray() as String tempArray = textBox1.Lines
'Loop through the array and send the contents of the array to debug window. For counter = 0 to tempArray.GetUpperBound(0) System.Diagnostics.Debug.WriteLine( tempArray(counter) ) Next End Sub [C#] public void ViewMyTextBoxContents() { // Create a string array and store the contents of the Lines property. string[] tempArray = new string [textBox1.Lines.Length]; tempArray = textBox1.Lines;
// Loop through the array and send the contents of the array to debug window. for(int counter=0; counter <= tempArray.Length;counter++) { System.Diagnostics.Debug.WriteLine(tempArray[counter]); } }
Public Sub ViewMyTextBoxContents()
Dim counter as Integer
'Create a string array and store the contents of the Lines property.
Dim tempArray() as String
tempArray = textBox1.Lines
'Loop through the array and send the contents of the array to debug window.
For counter = 0 to tempArray.GetUpperBound(0)
System.Diagnostics.Debug.WriteLine( tempArray(counter) )
Next
End Sub
[C#]
public void ViewMyTextBoxContents()
{
// Create a string array and store the contents of the Lines property.
string[] tempArray = new string [textBox1.Lines.Length];
tempArray = textBox1.Lines;
// Loop through the array and send the contents of the array to debug window.
for(int counter=0; counter <= tempArray.Length;counter++)
{
System.Diagnostics.Debug.WriteLine(tempArray[counter]);
}
}