In the top Form1 level I have:
List<float> cyclicSelectedIndex = new List<float>(2);
int currentCyclicIndex;
In the constructor I have:
currentCyclicIndex = 0;
And this is the mouse down event where I have the selectedIndex when clicking on a point:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left) {
label1.Text = e.X.ToString();
label2.Text = e.Y.ToString();
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
// find the index that is closest to the current mouse location
MinDist = float.MaxValue;
for (idx = 0; idx < Point_X.Count; ++idx) {
float dx = Point_X[idx] - e.X;
float dy = Point_Y[idx] - e.Y;
float dist = (float)Math.Sqrt(dx * dx + dy * dy);
if (dist < MinDist) {
MinDist = dist;
selectedIndex = idx;
}
}
if (MinDist < 5) {
mouseMove = true;
OriginalX = Point_X[(int)selectedIndex];
OriginalY = Point_Y[(int)selectedIndex];
}
}
}
I want in the mouse down event in cyclic way logic to add the selectedIndex to the List according the INT variable pointing.
Once the int is 0 and once its 1. And each time it will contain or point at another selectedIndex number which meaning I clicked on two different points.
So if I click on one point it will add the point selectedIndex to the cyclic List at index 0 using the INT variable.
And then if I click on any other point it will add the other point selectedIndex to to index 1 in the cyclic List using the INT variable.
The idea is to make a cyclic List so when I click a two points it will not delete the last index but will puse the last one so once I click a point it will add the selectedIndex to index 0 clicked on another point it will add the selectedIndex to index 0 and move the other index to 1 and so on. Cyclic.
I need to make something in the mouse down event to add some code and make that when I click on a point like now and the I have the selectedIndex so if I click after it on another point I will have a new variable with the other clicked point index for example: selectedIndex1
And then I want in the mouse down event to use the int variable to add to the List<> each time the last selectedIndex or selectedIndex1 to the place in the List using the int.
A list is empty after creation, even if you specify a size in the constructor. This space is only the initially reserved space for the later addition of items. You have to add items with
Add.If you have a fixed size, use an array instead
Increment the index like this, using a modulo operation
The index will cycle like this: 0, 1, 0, 1, …
UPDATE
You can use the
PointFstructure to store x/y-coordinates asfloatvalues.After having found a OriginalX/Y, add a element to the list if its size is smaller than 2, or change a existing element at a cyclic position otherwise.
You can access a point coordinate in the list like this:
UPDATE #2
If you want to store the index, define your list as list of
int, not offloatorPointF