我怎么说呢,检测列表框中的特定文本并将其替换为特定文本。例如:
private void timer1_Tick(object sender, EventArgs e)
{
if(listBox1.Text.Contains("Hi"))
{
// replace with Hello
}
}
Run Code Online (Sandbox Code Playgroud)
在 中WinForms,你可以这样做:
if(listBox1.Items.Cast<string>().Contains("Hi")){ //check if the Items has "Hi" string, case each item to string
int a = listBox1.Items.IndexOf("Hi"); //get the index of "Hi"
listBox1.Items.RemoveAt(a); //remove the element
listBox1.Items.Insert(a, "Hello"); //re-insert the replacement element
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14963 次 |
| 最近记录: |