はない非常に明確であるが、あなたのコメントを読んで、このために特別に探して:
foreach(var item in listBoxLat.Items && var item2 in listBoxLong.Items)
{
e.Graphics.DrawEllipse(myPen, Convert.ToInt16(item), Convert.ToInt16(item2), 2, 2);
}
私はあなたが1つのリストの最初の項目を実行しようとしていると思います最初の項目を他のリストに追加して続行します。あなたはそれらを同期させています。
タプルを使用してタプルのリストに格納する方がよいでしょう。そして、あなたは "Graphics.DrawEllipse
"の仕組みを理解する必要があります。そこで私は以下の文書の要約を書いた。
次のコードが動作する可能性がありますので、私は現在作業中ですのでテストできませんでした。
List<Tuple<int, int>> myTuple = new List<Tuple<int, int>>();
private void timer1_Tick(object sender, EventArgs e)
{
pictureBoxPath.Refresh();
myTuple.Add(new Tuple<int, int>(gPathBoylam, gPathEnlem));
}
//
// Summary:
// Draws an ellipse defined by a bounding rectangle specified by coordinates
// for the upper-left corner of the rectangle, a height, and a width.
//
// Parameters:
// pen:
// System.Drawing.Pen that determines the color, width,
// and style of the ellipse.
//
// x:
// The x-coordinate of the upper-left corner of the bounding rectangle that
// defines the ellipse.
//
// y:
// The y-coordinate of the upper-left corner of the bounding rectangle that
// defines the ellipse.
//
// width:
// Width of the bounding rectangle that defines the ellipse.
//
// height:
// Height of the bounding rectangle that defines the ellipse.
//
// Exceptions:
// System.ArgumentNullException:
// pen is null.
private void pictureBoxPath_Paint(object sender, PaintEventArgs e)
{
Pen myPen = new Pen(Color.Red, 3); // Create pen
if(myTuple != null && myTuple.Any())
{
foreach (var tuple in myTuple)
{
Rectangle rect = new Rectangle(Convert.ToInt16(tuple.Item1), Convert.ToInt16(tuple.Item2), 2, 2); // Create rectangle for ellipse
e.Graphics.DrawEllipse(myPen, rect); // Draw ellipse to screen
}
}
}
だからあなたは何のエラーを取得している、「AND」という質問には、私には意味を作るのではなく、に関係なく、どのような問題あなたは見ていますか?リストボックスアイテムをintとしてキャストしようとしているのを見ましたが、それを試したことはありませんが、item.valueの後に置く必要があると思います。 – Trey
あなたの問題の明確な説明を入力してください。 – MetaColon
foreachループは、1つのことと1つのことだけを行うことを意図しています:いくつかのコレクションの各要素をループします。それは 'foreach(..)'部分内の別の条件をチェックしたり、チェックしたりすることができません。 2つのコレクションをループしたい場合は、行ったようにコレクションをネストする必要があります。または、forなどの別のループを使用します。 –