EDN Admin
Well-known member
In Form1 rivate void button3_Click(object sender, EventArgs e)
{
//To add/create here the delete point button event !!!
//***** When clicking on a point and delete it it will delete the current point. When clicking on a point then on another point and click delete it will delete two different points the last two points
//clicked before to check why ******* \
wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
numberOfPoints--;
label16.Text = numberOfPoints.ToString();
button3.Enabled = false;
/* if (wireObjectCoordinates1 == null)
wireObjectCoordinates1 = new WireObjectCoordinates() { FrameNumber = currentFrameIndex };
WireObjectCoordinatesCloneFrame();
wireObjectAnimation1._coordinatesList.Add(wireObjectCoordinates1);*/
addFrame = true;
pictureBox1.Invalidate();
}
cyclicSelectedIndex is List<int>
The function : wireObject1.DeletePoint get int x , int y
numberOfPoints in this case is int contain 1 only 1 point
addFrame = true if it will be false it will erase all the points rivate void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
moveCounter++;
label6.Text = moveCounter.ToString();
if (addFrame == true)
{
addFrame = false;
WireObjectGraphics.Draw(wireObject1, g);
}
}
Now in the wireObject class i did i have the function ublic void DeletePoint(int x, int y)
{
for (int i = 0; i < _point_X.Count; i++)
{
if ((_point_X == x && _point_Y == y) || (_point_X == y && _point_Y == x)) //|| y == -1 || x == -1) // Deletion of points is working now. When clicking on a point it delete the specific point.
// to make that it wil close enable false button 3 delete point if deleted any point so i can delete only point i clicked on.
{
woc.Point_X.RemoveAt(i);
woc.Point_Y.RemoveAt(i); // *** If there is only one point or left one point need to click on it teice to delete it to check why !!!!!
}
}
}
But this comparison : if ((_point_X == x && _point_Y == y) || (_point_X == y && _point_Y == x)) never happen . If i remember right it should compare indexs and then to remove the right index .
For example on one point i select the point and click on delete using a breakpoint in the DeletePoint function i see that x = 0 and y = -1
_point_X and _point_Y are List<float) each one contain in this example one index with the point coordinates.
Same in : woc.Point_X.RemoveAt(i); and woc.Point_Y.RemoveAt(i); both contain 1 index each one the coordinate of the point .
This is the code of the woc class :using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AnimationEditor
{
class WireObjectCoordinates
{
public List<float> Point_X = new List<float>();
public List<float> Point_Y = new List<float>();
public WireObjectCoordinates()
{
}
public WireObjectCoordinates(WireObjectCoordinates w)
{
Point_X.AddRange(w.Point_X);
Point_Y.AddRange(w.Point_Y);
}
public void Set(WireObjectCoordinates w)
{
if (w == null)
{
}
else
{
for (int i = 0; i < Point_X.Count; i++)
{
Point_X = w.Point_X;
Point_Y = w.Point_Y;
}
}
}
}
}
Once i click on the add a button rivate void button1_Click(object sender, EventArgs e)
{
addFrame = true;
halfX = pictureBox1.ClientRectangle.Width / 2;
halfY = pictureBox1.ClientRectangle.Height / 2;
Random rnd = new Random();
offsetX = rnd.Next(-10, 10);
offsetY = rnd.Next(-10, 10);
if (wireObject1 != null)
{
wireObject1.addPoint(halfX + offsetX, halfY + offsetY);
}
In the wireObject class ublic void addPoint(float x, float y)
{
woc.Point_X.Add(x);
woc.Point_Y.Add;
}
The cyclic Lists are updating once i make mouse down click to select the specific point i want to delete rivate void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
label1.Visible = true;
label4.Visible = true;
// find the index that is closest to the current mouse location
/* if (wireObject1._point_X.Count < 2 || wireObject1._point_Y.Count < 2)
{
button2.Enabled = false;
}*/
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 (currentCyclicIndex == 0)
{
cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex; // Connecting points is working. But after many connections its moving slowly and sometimes show nig red X with white background
// to check why
currentCyclicIndex++;
}
else
{
cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex;
if (currentCyclicIndex == 1)
{
currentCyclicIndex = 0;
}
}*/
if ((cyclicSelectedIndex[0] == cyclicSelectedIndex[1]) || (cyclicSelectedIndex[0] == -1) || (cyclicSelectedIndex[1] == -1))
// To check why when clicking on connected point with al ine its blinking enable true the button 2 for milisecond !!!!!
// Still connecting points dosent work good yet sometimes need to click twice in a row to delete a line and to check all possible ways and bugs.
{
button2.Enabled = false;
}
else
{
button2.Enabled = true;
}
for (int i = 0; i < wireObject1._connectionstart.Count; i++) // To check why wireObject1._connectionstart.Count List is empty ! where do i add something to list if at all ?! A bug !!!!!
{
if ((wireObject1._connectionstart == cyclicSelectedIndex[0] && wireObject1._connectionend == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart == cyclicSelectedIndex[1] && wireObject1._connectionend == cyclicSelectedIndex[0]) ||
wireObject1._connectionstart == cyclicSelectedIndex[0] || wireObject1._connectionend == cyclicSelectedIndex[1] ||
wireObject1._connectionstart == cyclicSelectedIndex[1] || wireObject1._connectionend == cyclicSelectedIndex[0])
{
//button2.Enabled = false;
button3.Enabled = false;
}
if ((wireObject1._connectionstart == cyclicSelectedIndex[0] && wireObject1._connectionend == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart == cyclicSelectedIndex[1] && wireObject1._connectionend == cyclicSelectedIndex[0]))
{
button2.Enabled = false; /// Dosent delete a connection when for example 3 point are connected with 3 lines like a tringale.
/// Also to make that when there are connections between points more then 2 like 3 points connected if i click on two connected points to turn on button4.
}
}
label13.Text = selectedIndex.ToString();
label13.Visible = true;
label14.Visible = true;
listView1.Items.Add(selectedIndex.ToString()).EnsureVisible();
}
}
}
}
}
}
But the point is never deleted . Nothing happen when i select the point and then click on the delete point button.
View the full article
{
//To add/create here the delete point button event !!!
//***** When clicking on a point and delete it it will delete the current point. When clicking on a point then on another point and click delete it will delete two different points the last two points
//clicked before to check why ******* \
wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
numberOfPoints--;
label16.Text = numberOfPoints.ToString();
button3.Enabled = false;
/* if (wireObjectCoordinates1 == null)
wireObjectCoordinates1 = new WireObjectCoordinates() { FrameNumber = currentFrameIndex };
WireObjectCoordinatesCloneFrame();
wireObjectAnimation1._coordinatesList.Add(wireObjectCoordinates1);*/
addFrame = true;
pictureBox1.Invalidate();
}
cyclicSelectedIndex is List<int>
The function : wireObject1.DeletePoint get int x , int y
numberOfPoints in this case is int contain 1 only 1 point
addFrame = true if it will be false it will erase all the points rivate void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
moveCounter++;
label6.Text = moveCounter.ToString();
if (addFrame == true)
{
addFrame = false;
WireObjectGraphics.Draw(wireObject1, g);
}
}
Now in the wireObject class i did i have the function ublic void DeletePoint(int x, int y)
{
for (int i = 0; i < _point_X.Count; i++)
{
if ((_point_X == x && _point_Y == y) || (_point_X == y && _point_Y == x)) //|| y == -1 || x == -1) // Deletion of points is working now. When clicking on a point it delete the specific point.
// to make that it wil close enable false button 3 delete point if deleted any point so i can delete only point i clicked on.
{
woc.Point_X.RemoveAt(i);
woc.Point_Y.RemoveAt(i); // *** If there is only one point or left one point need to click on it teice to delete it to check why !!!!!
}
}
}
But this comparison : if ((_point_X == x && _point_Y == y) || (_point_X == y && _point_Y == x)) never happen . If i remember right it should compare indexs and then to remove the right index .
For example on one point i select the point and click on delete using a breakpoint in the DeletePoint function i see that x = 0 and y = -1
_point_X and _point_Y are List<float) each one contain in this example one index with the point coordinates.
Same in : woc.Point_X.RemoveAt(i); and woc.Point_Y.RemoveAt(i); both contain 1 index each one the coordinate of the point .
This is the code of the woc class :using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AnimationEditor
{
class WireObjectCoordinates
{
public List<float> Point_X = new List<float>();
public List<float> Point_Y = new List<float>();
public WireObjectCoordinates()
{
}
public WireObjectCoordinates(WireObjectCoordinates w)
{
Point_X.AddRange(w.Point_X);
Point_Y.AddRange(w.Point_Y);
}
public void Set(WireObjectCoordinates w)
{
if (w == null)
{
}
else
{
for (int i = 0; i < Point_X.Count; i++)
{
Point_X = w.Point_X;
Point_Y = w.Point_Y;
}
}
}
}
}
Once i click on the add a button rivate void button1_Click(object sender, EventArgs e)
{
addFrame = true;
halfX = pictureBox1.ClientRectangle.Width / 2;
halfY = pictureBox1.ClientRectangle.Height / 2;
Random rnd = new Random();
offsetX = rnd.Next(-10, 10);
offsetY = rnd.Next(-10, 10);
if (wireObject1 != null)
{
wireObject1.addPoint(halfX + offsetX, halfY + offsetY);
}
In the wireObject class ublic void addPoint(float x, float y)
{
woc.Point_X.Add(x);
woc.Point_Y.Add;
}
The cyclic Lists are updating once i make mouse down click to select the specific point i want to delete rivate void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
label1.Visible = true;
label4.Visible = true;
// find the index that is closest to the current mouse location
/* if (wireObject1._point_X.Count < 2 || wireObject1._point_Y.Count < 2)
{
button2.Enabled = false;
}*/
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 (currentCyclicIndex == 0)
{
cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex; // Connecting points is working. But after many connections its moving slowly and sometimes show nig red X with white background
// to check why
currentCyclicIndex++;
}
else
{
cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex;
if (currentCyclicIndex == 1)
{
currentCyclicIndex = 0;
}
}*/
if ((cyclicSelectedIndex[0] == cyclicSelectedIndex[1]) || (cyclicSelectedIndex[0] == -1) || (cyclicSelectedIndex[1] == -1))
// To check why when clicking on connected point with al ine its blinking enable true the button 2 for milisecond !!!!!
// Still connecting points dosent work good yet sometimes need to click twice in a row to delete a line and to check all possible ways and bugs.
{
button2.Enabled = false;
}
else
{
button2.Enabled = true;
}
for (int i = 0; i < wireObject1._connectionstart.Count; i++) // To check why wireObject1._connectionstart.Count List is empty ! where do i add something to list if at all ?! A bug !!!!!
{
if ((wireObject1._connectionstart == cyclicSelectedIndex[0] && wireObject1._connectionend == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart == cyclicSelectedIndex[1] && wireObject1._connectionend == cyclicSelectedIndex[0]) ||
wireObject1._connectionstart == cyclicSelectedIndex[0] || wireObject1._connectionend == cyclicSelectedIndex[1] ||
wireObject1._connectionstart == cyclicSelectedIndex[1] || wireObject1._connectionend == cyclicSelectedIndex[0])
{
//button2.Enabled = false;
button3.Enabled = false;
}
if ((wireObject1._connectionstart == cyclicSelectedIndex[0] && wireObject1._connectionend == cyclicSelectedIndex[1]) ||
(wireObject1._connectionstart == cyclicSelectedIndex[1] && wireObject1._connectionend == cyclicSelectedIndex[0]))
{
button2.Enabled = false; /// Dosent delete a connection when for example 3 point are connected with 3 lines like a tringale.
/// Also to make that when there are connections between points more then 2 like 3 points connected if i click on two connected points to turn on button4.
}
}
label13.Text = selectedIndex.ToString();
label13.Visible = true;
label14.Visible = true;
listView1.Items.Add(selectedIndex.ToString()).EnsureVisible();
}
}
}
}
}
}
But the point is never deleted . Nothing happen when i select the point and then click on the delete point button.
View the full article