如果我选择多个项目,我如何为列表框中的每个项目制作任务
本文关键字:项目 任务 选择 如果 列表 | 更新日期: 2023-09-27 18:04:13
首先这是listBox选择的索引更改事件:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
label4.Text = listBox1.SelectedItem.ToString();
string startTag = "Url: ";
string endTag = " ---";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
int index = 0;
index = label4.Text.IndexOf(startTag, index);
int start = index + startTagWidth;
index = label4.Text.IndexOf(endTag, start + 1);
string g = label4.Text.Substring(start, index - start);
label4.Text = g;
mainUrl = g;
}
}
通过添加以下方法解决:
private string GetUrl(object obj)
{
string startTag = "Url: ";
string endTag = " ---";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
int index = 0;
index = obj.ToString().IndexOf(startTag, index);
int start = index + startTagWidth;
index = obj.ToString().IndexOf(endTag, start + 1);
string g = obj.ToString().Substring(start, index - start);
mainUrl = g;
return mainUrl;
}
在DoWork事件中像这样使用它:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
object input = e.Argument;
string f = GetUrl(input);
this.Invoke(new MethodInvoker(delegate { label2.Text = "Website To Crawl: "; }));
this.Invoke(new MethodInvoker(delegate { label4.Text = f; }));
if (offlineOnline == true)
{
offlinecrawling(f, levelsToCrawl, e);
}
else
{
webCrawler(f, levelsToCrawl, e);
}
}