MSDNS의 How to: Create a Multiline TextBox Control과 유사한 다중 텍스트 상자를 사용한다고 가정하면 SelectedText 속성을 사용하여 사용자가 선택한 텍스트를 검색 할 수 있습니다. 내가 (페이지 라인 inbetween) 아래의 경우 선은
즉 \r\n
로 구분됩니다
test0
TEST1
그리고 선택한 라인 test0
및(3210), 다음 SelectedText
는 test0\r\ntest1
될 것이다.
그런 다음 \r\n
에 분할 선택한 각 행을 검색 할 수 있습니다.
// Retrieve selected lines
List<string> SelectedLines = Regex.Split(txtNewURLs.SelectedText, @"\r\n").ToList();
// Check for nothing, Regex.Split returns empty string when no text is inputted
if(SelectedLines.Count == 1) {
if(String.IsNullOrWhiteSpace(SelectedLines[0])) {
SelectedLines.Remove("");
}
}
// Retrieve all lines from textbox
List<string> AllLines = Regex.Split(txtNewURLs.Text, @"\r\n").ToList();
// Check for nothing, Regex.Split returns empty string when no text is inputted
if(AllLines.Count == 1) {
if(String.IsNullOrWhiteSpace(AllLines[0])) {
AllLines.Remove("");
}
}
string SelectedMessage = "The following lines have been selected";
int numSelected = 0;
// Find all selected lines
foreach(string IndividualLine in AllLines) {
if(SelectedLines.Any(a=>a.Equals(IndividualLine))) {
SelectedMessage += "\nLine #" + AllLines.FindIndex(a => a.Equals(IndividualLine));
// Assuming you store each line status in an List, change status to 1
LineStatus[AllLines.FindIndex(a => a.Equals(IndividualLine));] = 1;
numSelected++;
}
}
MessageBox.Show((numSelected > 0) ? SelectedMessage : "No lines selected.");
당신은 – Arshad
이 0과 더 나은 당신이 원하는 또는 각 라인 0과 1로 설정해야합니다 변수를해야합니까 무엇인지 설명에만 가상 1이 시나리오에서 목록 상자를 사용할 수 있습니까? 인 selectionchanged도 편리 할 것입니다 곳 –
이다, 그러나 나는 텍스트 상자에 존재하지 않는 확신 해요. 이 작업을 수행 할 수있는 사용자 지정 컨트롤을 만들 수 있습니다. 이 목록 상자 컨트롤을 사용해보십시오 – metalhead