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 8559839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:08:46+00:00 2026-06-11T16:08:46+00:00

Ok, so right now when i click on the grid it goes through all

  • 0

Ok, so right now when i click on the grid it goes through all the ‘paths’ on the grid and checks if they’re an ellipse and if the mouse is over them, and if there’s 2 selected it calculated the distance apart…. but if i get 50+ points on the grid, clicking on a point does nothing…. Is there any more efficient way of doing this ?

Here’s my code:

foreach (var x in GraphPanel.Children)
{
     try
     {
         if (((Path)x).IsMouseOver && ((Path)x).Data.ToString() == "System.Windows.Media.EllipseGeometry")
         {
            listViewPoints.SelectedItems.Add(listViewPoints.Items[PointIndex]);
            var converter = new System.Windows.Media.BrushConverter();
            var brush = (System.Windows.Media.Brush)converter.ConvertFromString("#FFB1D100");
                    ((Path)x).Stroke = brush;
                    ((Path)x).StrokeThickness = 8;

            if (listViewPoints.SelectedItems.Count == 2)
            {
                 double diffX;
                 double diffY;

                 double ptAX = ((Points)listViewPoints.SelectedItems[0]).A;
                 double ptAY = ((Points)listViewPoints.SelectedItems[0]).B;
                 double ptBX = ((Points)listViewPoints.SelectedItems[1]).A;
                 double ptBY = ((Points)listViewPoints.SelectedItems[1]).B;

                 if (ptAX > ptBX)
                 {
                     diffX = ptAX - ptBX;
                 }
                 else
                 {
                     diffX = ptBX - ptAX;
                 }
                 if (ptAY > ptBY)
                 {
                     diffY = ptAY - ptBY;
                 }
                 else
                 {
                     diffY = ptBY - ptAY;
                 }
                 //the distance between the points = sqr/-diff in x squared + diff in y squared
                 double result = Math.Sqrt(Math.Pow(diffX,2) + Math.Pow(diffY,2));
                 CalculatedDistanceApart.Content = "Distance Apart: " + result.ToString() + "'";
             }
        }

        if (((Path)x).Data.ToString() == "System.Windows.Media.EllipseGeometry")
        {
            PointIndex++;
        }
    }
    catch { }
}
  • 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-11T16:08:47+00:00Added an answer on June 11, 2026 at 4:08 pm

    Well I don’t know about your slow IsMouseOver, but the whole thing can certainly be sped and tidied up:

    //why make these for every item?
    var converter = new System.Windows.Media.BrushConverter(); 
    var brush = (System.Windows.Media.Brush)converter.ConvertFromString("#FFB1D100"); 
    
    foreach (var x in GraphPanel.Children) 
    { 
        //this is tidier, but what if it's not a Path, is that possible?
        var path = (Path)x;
    
        //jump out here if it's not the right type, reduces nesting and removes one comparison
        if(!(path.Data is System.Windows.Media.EllipseGeometry)) continue;
    
         try
         {
             if (path.IsMouseOver)
             { 
                listViewPoints.SelectedItems.Add(listViewPoints.Items[PointIndex]); 
                path.Stroke = brush; 
                path.StrokeThickness = 8;      
                if (listViewPoints.SelectedItems.Count == 2) 
                {
                     double ptAX = ((Points)listViewPoints.SelectedItems[0]).A; 
                     double ptAY = ((Points)listViewPoints.SelectedItems[0]).B; 
                     double ptBX = ((Points)listViewPoints.SelectedItems[1]).A; 
                     double ptBY = ((Points)listViewPoints.SelectedItems[1]).B; 
    
                     //you're going to square these, so negatives don't matter
                     double diffX = ptAX - ptBX;
                     double diffY = ptAY - ptBY;
    
                     //the distance between the points = sqr/-diff in x squared + diff in y squared 
                     //don't use Math.Pow for squaring
                     double result = Math.Sqrt(diffX*diffX + diffY*diffY); 
                     CalculatedDistanceApart.Content = "Distance Apart: " + result + "'"; 
                     //are we done now?
                 } 
            } 
            PointIndex++; 
    
        } 
        catch { } 
    } 
    

    Math.Pow(x,2) vs x * x

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now the problem is that the first time when I click the image,
Right now I wrote download code in Masterpage code behind for Menu item click.
I am working on a memory matching game. Right now, when the user clicks
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
Right now I have a script that will get the last five files in
Right now, the label for my Activity has the name of the current Activity.
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.

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.