이 예제는 TextBox에서 텍스트 줄의 컬렉션을 가져오는 방법을 보여 줍니다.
예시
다음 예제는 TextBox를 인수로 가져오는 단순한 메서드를 보여 주고 TextBox에 텍스트 줄을 포함하는 StringCollection을 반환합니다. LineCount 속성은 현재 TextBox에 몇 줄이 있는지 확인하는 데 사용되며 GetLineText 메서드는 각 줄을 추출하고 이를 줄 컬렉션에 추가하는 데 사용됩니다.
StringCollection GetLinesCollectionFromTextBox(TextBox textBox)
{
StringCollection lines = new StringCollection();
// lineCount may be -1 if TextBox layout info is not up-to-date.
int lineCount = textBox.LineCount;
for (int line = 0; line < lineCount; line++)
// GetLineText takes a zero-based line index.
lines.Add(textBox.GetLineText(line));
return lines;
}
참고하십시오
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET Desktop feedback