Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:48:00+00:00 2026-06-06T06:48:00+00:00

I have two List s of type int where I store point coordinates called

  • 0

I have two Lists of type int where I store point coordinates called Point_X and Point_Y.

This is the delete method in the new class:

public void DeletePoint(int x, int y)
{
    for (int i = 0; i < Point_X.Count; i++)
    {
        if ((i == x) && (i == y) || y == -1 || x == -1) 
        {
            Point_X.RemoveAt(i);
            Point_Y.RemoveAt(i); 
        }
        else
        {
        }
    }
}

In x and y, I’m getting the index of the point I clicked. If I add two points and click on one of them so I’m getting two indexes of the point, e.g. x will be 0 and y will be -1.

Now I’m running through the Point_X list and I need to check for all situations and compare the indexes I’m getting with the indexes in the lists Point_X and Point_Y and then it should remove the point I clicked on.

This if doesn’t seem to be working: if ((i == x) && (i == y) || y == -1 || x == -1).
If I have two points in pictureBox1 and I click on point number 2 and try to delete it, it doesn’t get removed the first time around. It does get removed the second time I click though.

This is the code of the button click in Form1 where I click to delete the point:

private void button3_Click(object sender, EventArgs e)
{           
    wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
    button3.Enabled = false;
}

This is the code where I click on the point I want to select in pictureBox1‘s MouseDown event:

private 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
        float t = wireObject1.GetIndexByXY(e.X, e.Y, 5);

        if (t == -1)
        {
            button3.Enabled = false;
        }
        else
        {
            button3.Enabled = true;
            {
                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]))
                        {
                             button2.Enabled = false;
                        }
                    }

                    label13.Text = selectedIndex.ToString();
                    label13.Visible = true;
                    label14.Visible = true;

                    listView1.Items.Add(selectedIndex.ToString()).EnsureVisible();
                }
            }
        }
    }
}

The problem is that the DeletePoint method in the new class doesn’t delete the point I clicked on unless I click on it twice.


And it’s logical if ((i == x) && (i == y)) since in some cases x is 1 and y is 0 so the variable (i) will never be also 0 and also 1 so I’m stuck here.

I don’t how to check for all situations – e.g. x is 1 and y is 0. There may be other scenarios to cover but I think the problem is somewhere in this if statement.


x = 1 , y = 1

Point_X >>> [0] = 331.0 , [1] = 212.0

Point_Y >>> [0] = 213.0 , [1] = 212.0

i = 0

This is the case when i have two points and i clicked on the second point.
It didnt do anything in the function in the new class it didnt remove the point.

Same for the first point it didnt remove it it didnt enter to the remove area.
This is when im using Alexei Levenkov idea sample for the If checking.

Now in Form1 when im clicking on a point in the pictureBox1 so in the mouse down event i have a variable(t) wich i calculate the index of the point in the new class:

public float GetIndexByXY( int x , int y , float tol)
        {
            for (idx = 0; idx < Point_X.Count; ++idx)
            {
                float dx = Point_X[idx] - x;
                float dy = Point_Y[idx] - y;
                float dist = (float)Math.Sqrt(dx * dx + dy * dy);

                if (dist < tol) return idx;

            }
            return -1;
        }

For example if i have one point and i click on it then variable(t) = 0

Then the List cyclicSelectedIndex have two cells/places in [0] i have 0 and in [1] i have -1 and currentCyclicIndex is now 1 and selectedIndex is 0 thats in Form1 in mouse down event. The mouse down event is just to mark wich point i want to delete.

In Form1 button click where i click to the delete the point:

private void button3_Click(object sender, EventArgs e)
        {



            wireObject1.DeletePoint(cyclicSelectedIndex[0],cyclicSelectedIndex[1]);
            button3.Enabled = false;

            pictureBox1.Invalidate();
        } 

cyclicSelectedIndex[0] = 0 and cyclicSelectedIndex[1] = -1

So in the new class in the DeletePoint function:

public void DeletePoint(int x, int y)
        {

            for (int i = 0; i < Point_X.Count; i++)
            {

                if ((Point_X[i] == x) && (Point_Y[i] == y) || y == -1 || x == -1) 
                {
                    Point_X.RemoveAt(i);
                    Point_Y.RemoveAt(i); 
                }
                else
                {
                }
            }



        }

x = 0 and y = -1

Now i need to remove the index 0 and -1 from the Lists: Point_x and Point_Y and each index in this Lists contain a coordinate of hte point i want to delete.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:48:01+00:00Added an answer on June 6, 2026 at 6:48 am

    Most likely you want to compare values of elements to x/y, not indexes:

    if ((Point_X[i] == x) && (Point_Y[i] == y) || y == -1 || x == -1)  
    

    Note it may be better to use class (struct if you know/have good reason) with X/Y properties and store them in one list:

    class MyPoint { public int X;public int Y;}
    List<MyPoint> point = new List<MyPoint>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists x1 and x2 of type double List<double> x1 = new
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have two complex (i.e. objects with string, int, double, List and other home
I have two lists of the same type. That type does not have an
Suppose I have two lists of type MyCustomType , a class which could be
I have two lists List that I need to combine in third list and
Let's say you have two collections of integers: IEnumerable<int> col1=new List<int> {2,3,3,5,7,11,11,11,13}; IEnumerable<int> col2=new
I have two array list. Each has list of Objects of type Employee. The
I have two list on my request on jsp. First one is productGroupName, and
i have two list, i wanted to update the second list while adding a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.