Reputation: 399
This is the code in Form1 of the pictureBox1 mouse down event:
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
label1.Visible = true;
label4.Visible = true;
if (wireObject1 == null)
{
}
else
{
float t = wireObject1.GetIndexByXY(e.X, e.Y, 5);
if (t == -1)
{
button3.Enabled = false;
}
else
{
if (pointDeletion == false)
{
button3.Enabled = true;
}
else
{
button3.Enabled = false;
}
{
selectedIndex = t;
mouseMove = true;
OriginalX = wireObject1._point_X[(int)selectedIndex];
OriginalY = wireObject1._point_Y[(int)selectedIndex];
if (cyclicSelectedIndex.Count() == 2)
{
cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex;
currentCyclicIndex++;
if (currentCyclicIndex == 2)
{
currentCyclicIndex = 0;
}
if ((cyclicSelectedIndex[0] == cyclicSelectedIndex[1]) || (cyclicSelectedIndex[0] == -1) || (cyclicSelectedIndex[1] == -1))
{
button2.Enabled = false;
}
else
{
button2.Enabled = true;
}
for (int i = 0; i < wireObject1._connectionstart.Count; i++)
{
if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0] && wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1] && wireObject1._connectionend[i] == cyclicSelectedIndex[0]) ||
wireObject1._connectionstart[i] == cyclicSelectedIndex[0] || wireObject1._connectionend[i] == cyclicSelectedIndex[1] ||
wireObject1._connectionstart[i] == cyclicSelectedIndex[1] || wireObject1._connectionend[i] == cyclicSelectedIndex[0])
{
button3.Enabled = false;
}
if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0] && wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1] && wireObject1._connectionend[i] == cyclicSelectedIndex[0]))
{
button2.Enabled = false;
}
if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[0]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[0]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[0]))
{
button4.Enabled = true;
}
else
{
button4.Enabled = false;
}
}
label13.Text = selectedIndex.ToString();
label13.Visible = true;
label14.Visible = true;
listView1.Items.Add(selectedIndex.ToString()).EnsureVisible();
}
}
}
}
}
}
I have a button click event, and when i click it's adding(drawing) a point on the pictureBox1
.
So i add/click 6 times and add 6 points.
Now i can drag them around the pictureBox1
area.
Then i click on another button to draw a line between two selected points.
When i make the click on a point in the pictureBox
mouse down event i select a point then select second point and click to connect them with a line.
In the end i have 6 points with 3 lines each two points are connected between them with a drawn line.
Now what i want to do in the pictureBox
mouse down event is that when ever i select two points which are connected with a line between them turn button4.enabled = true
.
If i clicked on any point which is not connect turn button4.enabled = false
.
So i tried to do it like this:
if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[0]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[0]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[0]))
{
button4.Enabled = true;
}
else
{
button4.Enabled = false;
}
But its not working in all cases .
Now:
wireObject1._connectionstart
is a List<int>
and also wireObject1._connectionend
is a List<int>
they are containing the starting and ending of each connected/line between two points.
cyclicSelectedIndex
is List<int>
. [0] contain the first clicked/selected point and [1] the second selected/clicked point.
What i did when i click on a point so its doing : wireObject1.GetIndexByXY which find the nearest center of the point i clicked so i know i selected this point i wanted and not one near it .
In the end what i need is to check when click/select two points if they are connected with a line(connection) between them button4.enabled = true
ELSE button4.enabled = false
.
( I know the code and descriptions are long tried to make it shortest as i can sorry )
Upvotes: 0
Views: 298
Reputation: 399
I had the right IF allready . Just added the button4.Enabled true or false and break;
if ((wireObject1._connectionstart[i] == cyclicSelectedIndex[0] && wireObject1._connectionend[i] == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart[i] == cyclicSelectedIndex[1] && wireObject1._connectionend[i] == cyclicSelectedIndex[0]))
{
button2.Enabled = false;
button4.Enabled = true;
break;
}
else
{
button4.Enabled = false;
}
From the tests i did so far everything seems to be working fine. I hope im right.
Thanks.
Upvotes: 0
Reputation: 11577
you need to debug and see what's going wrong. it should pop to your eye if you do it step by step. as it seems, you are doing wireObject1.GetIndexByXY(e.X, e.Y, 5);
witch probably don't return the right value, or your if statement doing some wired stuff, like checking if a dot is connected to itself:
wireObject1._connectionstart[i] == cyclicSelectedIndex[1]) && (wireObject1._connectionend[i] == cyclicSelectedIndex[1]
how can an single index be the start and end of a point. to make long story short, run the method line by line, see that the index are inserted to the data structure properly, and check the variables on the if statement.
Upvotes: 1