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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:57:01+00:00 2026-06-18T03:57:01+00:00

Windows Forms Application: This has been puzzling me for hours. What I am ATTEMPTING

  • 0

Windows Forms Application:

This has been puzzling me for hours. What I am ATTEMPTING to do is when i hold down on a label, it moves the form.

    private void label1_MouseUp(object sender, MouseEventArgs e)
    {
        KeepMoving = false;
    }

    private void label1_MouseDown(object sender, MouseEventArgs e)
    {
        KeepMoving = true;
    }

    private void label1_MouseMove(object sender, MouseEventArgs e)
    {
        if (KeepMoving == true)
            this.Location = new Point(MousePosition.X - (e.X + SystemInformation.FrameBorderSize.Width + label1.Left), MousePosition.Y - (e.Y + SystemInformation.CaptionHeight + label1.Top));

    }

is what i’m using (with a public bool KeepMoving of course.)

All works fine if I remove the e.X and e.Y, but then it is relative to the position of the top left of the label, however I want the location on the label itself.

When I use a messagebox to show me coordinates of e.X and e.Y on label, the numbers are correct showing me where on the label i clicked. When I use the point in the code above, no matter where on the label i click, the number doesn’t change, and when i attempt to move it it shoots up into the 30k+ range.

Why doesn’t the MouseEventArgs work in my equation? Sorry if i described poorly i tried the best i could.

  • 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-18T03:57:02+00:00Added an answer on June 18, 2026 at 3:57 am

    Keep track of the intiial offset from the top-left corner of the Label and adjust the Form’s location accordingly.

        public bool KeepMoving = false;
        private Point offset;
    
        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            KeepMoving = true;
            offset = new Point(e.X, e.Y);
        }
    
        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            KeepMoving = false;
        }
    
        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (KeepMoving)
            {
                Left += e.X - offset.X;
                Top += e.Y - offset.Y;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application is a Windows Forms .NET 4 C# TCP/IP server. It has been
I am using this text editor for my windows forms application This works great
We are currently developing a Windows Forms application in VS 2008 C#. This application
In a Windows Forms application I kill a process like this: Process[] ps =
In System.Windows.Forms.Application there are two properties called LocalUserAppDataPath and UserAppDataPath . On this computer
I have a .NET application that contains a checkbox (System.Windows.Forms.Checkbox). This component (WindowsForms10.BUTTON.app.0.378734a1) is
I've got an ASP.NET (.NET 4.0) application that uses Windows Forms Authentication. This authenticates
I have a C# Windows Form application that contains a menu with this event:
I am using C# with a Windows Application Form. In this I have a
I have a windows form without running it in an application. this is the

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.