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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:20:53+00:00 2026-06-04T09:20:53+00:00

l have problem with my c# winform project. In my project I have a

  • 0

l have problem with my c# winform project.

In my project I have a function that switches the location of buttons to their old location if they are in the same area.

private void myText_MouseUp(object sender, MouseEventArgs e)
{

Point q = new Point(0, 0);
        Point q2 = new Point(0, 0);
        bool flag = false;
        int r = 0;
        foreach (Control p in this.Controls)
        {
            for (int i = 0; i < counter; i++)
            {
                if (flag)
                {
                    if (p.Location.X == locationx[i] && p.Location.Y == locationy[i])
                    {
                        oldx = e.X;
                        oldy = e.Y;
                        flag = true;
                        r = i;
                    }
                }
            }
        }
        foreach (Control p in this.Controls)
        {
            for (int j = 0; j < counter; j++)
            {
                if ((locationx[j] == p.Location.X) && (locationy[j] == p.Location.Y))
                {
                    Point arrr = new Point(oldx, oldy);
                    buttons[j].Location = arrr;
                    buttons[r].Location = new Point(locationx[j], locationy[j]);
                }
            }
        }
}
   The problem with this code is that if they are in the same area, the buttons do not switch their locations.  Instead they goes to the last button location.

If someone could help me that will help me alot 🙂

  • 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-04T09:20:54+00:00Added an answer on June 4, 2026 at 9:20 am

    The if statement always evaluates to true. This means that the final j loop will do this:

    // last time round the i loop, i == counter-1
    // and q == new Point(locationx[counter-1], locationy[counter-1])
    for (int j = 0; j < counter; j++)
    {
        Point q2 = new Point(locationx[j], locationy[j]);
        buttons[i].Location = q2;
        buttons[j].Location = q;
    }
    

    The net result of this is that every button’s Location is set to q, which is

    new Point(locationx[counter-1], locationy[counter-1])
    

    Why does the if statement always evaluate to true. Well, first of all let’s look at a couple of the or clauses in the if statement:

    || ((q.Y >= q2.Y) && (q.X <= q2.X))
    || ((q.Y >= q2.Y) && (q.X == q2.X))
    

    This is equivalent to

    || ((q.Y >= q2.Y) && (q.X <= q2.X))
    

    The line containing the == test has absolutely no impact on the final result of the condition. In fact all the lines containing == can be similarly treated. This leaves:

    || ((q.Y >= q2.Y) && (q.X <= q2.X))
    || ((q.Y >= q2.Y) && (q.X >= q2.X))
    || ((q.Y <= q2.Y) && (q.X >= q2.X))
    || ((q.Y <= q2.Y) && (q.X <= q2.X))
    

    We can condense

    || ((q.Y >= q2.Y) && (q.X <= q2.X))
    || ((q.Y >= q2.Y) && (q.X >= q2.X))
    

    into

    || ((q.Y >= q2.Y)
    

    and similarly

    || ((q.Y <= q2.Y) && (q.X >= q2.X))
    || ((q.Y <= q2.Y) && (q.X <= q2.X))
    

    is the same as

    || ((q.Y <= q2.Y)
    

    Combine

    || ((q.Y >= q2.Y)
    || ((q.Y <= q2.Y)
    

    and you can see that the if condition always evaluates to true.

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

Sidebar

Related Questions

I have problem with my C# winform project. I have function that draw squares:
I have problem with fancybox. I want to write a function that will run
I have a winform project that is using a devexpress layout control and I
I have a WinForm project that I want to be usable as a console
I have a problem in my C# winform project. In my project I have
I have a problem with winform application which uses threads to update the UI.
I have simple WinForms application where modifying Windows Registry. The problem is that in
I have a project where a user for the company will use a winform
Project: Winforms, .NET framework: 3.5 (Visual Studio 2008) My problem is: I have a
Project Structure I have a silverlight project SLProj, that references a silverlight class library

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.