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

  • Home
  • SEARCH
  • 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 7686605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:31:06+00:00 2026-05-31T19:31:06+00:00

In the top Form1 level I have: List<float> cyclicSelectedIndex = new List<float>(2); int currentCyclicIndex;

  • 0

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.

  • 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-05-31T19:31:07+00:00Added an answer on May 31, 2026 at 7:31 pm

    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.

    List<int> list = new List<int>();
    list.Add(10);
    list.Add(7);
    

    If you have a fixed size, use an array instead

    int[] cyclicArray = new int[2];
    int index = 0;
    

    Increment the index like this, using a modulo operation

    index = (index + 1) % 2;
    

    The index will cycle like this: 0, 1, 0, 1, …

    cyclicArray[index] = someValue;
    

    UPDATE

    You can use the PointF structure to store x/y-coordinates as float values.

    List<PointF> cyclicPoints = new List<PointF>(2);
    int currentCyclicIndex;
    

    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.

    PointF point = new PointF(OriginalX, OriginalY);
    if (cyclicPoints.Count < 2) {
        cyclicPoints.Add(point);
    } else {
        cyclicPoints[currentCyclicIndex] = point;
        currentCyclicIndex = (currentCyclicIndex + 1) % 2;
    }
    

    You can access a point coordinate in the list like this:

    float x = cyclicPoints[0].X;
    float y = cyclicPoints[0].Y;
    

    UPDATE #2

    If you want to store the index, define your list as list of int, not of float or PointF

    List<int> cyclicSelectedIndex = new List<int>(2); 
    if (cyclicSelectedIndex.Count < 2) {
        cyclicSelectedIndex.Add((int)selectedIndex);
    } else {
        cyclicSelectedIndex[currentCyclicIndex] = (int)selectedIndex;
        currentCyclicIndex = (currentCyclicIndex + 1) % 2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms application that uses show multiple top-level windows: Form1 form1 =
I have a top-level page called ReceiveItem . Within that page, I have a
I have the following content types: Camp - the top level type Registration Information
Given a gem that defines top-level classes that clash with some code I have
I created a new module and a new top level menu item in the
In my application I have a Form that for one of the top level
Currently, I'm trying to have a top-level window in Windows Forms with a custom
I have the following setup. The folder itext is in the top level in
I have found the Form.TopMost property but it puts the form on top of
I have a form that will multiple Panel controls stacked on top of each

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.