こんにちは、2 つの listBox から 1 つの listBox に項目を追加するにはどうすればよいですか
例: listBox1 には Hello listBox2 には World! が含まれます。したがって、listbox3 で button1 をクリックすると、Hello World! が表示されます。並んでいるが、新しい行のようなものではない
こんにちは
世界!
private void button2_Click(object sender, EventArgs e)
{
listBox3.Items.Add(listBox1.Items + listBox2.Items);
}
2つのlistBox.itemsからHttpWebRequestを作成する方法がもう1つあります
private void button1_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create(listBox1.Items + listBox2.Items);
}
例: listBox1 を含むhttp://test.com
listBox2 を含む/index.html
したがって、button1 がクリックされると、listBox1 と listBox2 の項目が 1 つの項目に結合されるのでhttp://test.com/index.html
、Web サイトにリクエストが送信されます。
そしてもう1つ、このコードがcatch (WebException x)で停止するのはなぜですか
なぜ false を返すのか; button1_click が void のときに機能しないので、ボタンを bool 型にしようとしましたが、listBox1 エラーが発生します。
private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create(listBox1.Items[i].ToString());
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
if (response.StatusCode == HttpStatusCode.OK)
{
listBox2.Items.Add(listBox1.Items[i]);
}
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
}
catch (WebException x)
{
listBox2.Items.Add("Error! " + x.Message);
}
}
どんな助けでも大歓迎ですありがとう。