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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:45:36+00:00 2026-05-27T01:45:36+00:00

With WinForms, is there a way to be alerted to a control changing location

  • 0

With WinForms, is there a way to be alerted to a control changing location with respect to the screen?

Say you have a Form with a button on it, and you would like to know when the button is moved from its current pixel location on the screen. If the button is moved to a different location on its parent Form you could obviously use the LocationChanged event, but if the Form is moved by the user, how do you know the button has visually moved?

In this simplified case the quick answer is to monitor the Form’s LocationChanged and SizeChanged events, but there can be an arbitrary number of levels of nesting so monitoring those events for each parent up the chain to the primary form is not feasible. Using a timer to check if the location changed also seems like cheating (in a bad way).

Short version:
Given only an arbitrary Control object, is there a way to know when that Control’s location changes on the screen, without knowledge of the control’s parent hierarchy?

An illustration, by request:

Illustration

Note that this “pinning” concept is an existing capability but it currently requires knowledge of the parent form and how the child control behaves; this is not the problem I am trying to solve. I would like to encapsulate this control tracking logic in an abstract Form that “pin-able” Forms can inherit from. Is there some message pump magic I can tap into to know when a control moves on the screen without having to deal with all the complicated parent tracking?

  • 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-27T01:45:36+00:00Added an answer on May 27, 2026 at 1:45 am

    I’m not sure why you would say tracking the parent chain “is not feasible”. Not only is it feasible, it’s the right answer and the easy answer.

    Just a quick hack at a solution:

    private Control         _anchorControl;
    private List<Control>   _parentChain = new List<Control>();
    private void BuildChain()
    {
        foreach(var item in _parentChain)
        {
            item.LocationChanged -= ControlLocationChanged;
            item.ParentChanged -= ControlParentChanged;
        }
    
        var current = _anchorControl;
    
        while( current != null )
        {
            _parentChain.Add(current);
            current = current.Parent;
        }
    
        foreach(var item in _parentChain)
        {
            item.LocationChanged += ControlLocationChanged;
            item.ParentChanged += ControlParentChanged;
        }
    }
    
    void ControlParentChanged(object sender, EventArgs e)
    {
        BuildChain();
        ControlLocationChanged(sender, e);
    }
    
    void ControlLocationChanged(object sender, EventArgs e)
    {
        // Update Location of Form
        if( _anchorControl.Parent != null )
        {
            var screenLoc = _anchorControl.Parent.PointToScreen(_anchorControl.Location);
            UpdateFormLocation(screenLoc);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to add a control (e.g. a button) to a Winforms
Is there an easy way to add nodes to a WinForms .NET TreeView control
Is there a way to display multi-line text in standard Winforms listview control?
I have a winforms image list which contains say like 200 images 256x256. I
Is there a way to render WinForms controls like Crystal Reports Viewer asynch, or
Is there a way I can generate form in WinForms or window in WPF
Is there a way to host/display a full WinForms form (not just a single
Is there a way, when creating a WinForms Custom Control/User Control, to get a
Is there a way to create a winforms app, that detects an open browser
Is there any way to add reference from one winforms to another winforms?? There

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.