Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Checking if control moved

Checking if control moved

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lustuyck
    wrote on last edited by
    #1

    Hello, I developed a user control, that creates a little form (X) and positions that form relative to the control. The control is placed on a windows form to test it. The idea is that when the windows main form is moved, the control is also moved (anchoring), but form X should move along. So what I do is catch the LocationChanged event of the ParentForm of the control, and in that event I reposition form X. This works ok. However, now I'm in the situation that the control is placed on something that has no ParentForm. Question: how can I detect if a control's screen coordinates are changing? So the position of the control inside its parent remains the same, but the screen coordinates change because the parent is moved. Can I detect such movement?

    H 1 Reply Last reply
    0
    • L lustuyck

      Hello, I developed a user control, that creates a little form (X) and positions that form relative to the control. The control is placed on a windows form to test it. The idea is that when the windows main form is moved, the control is also moved (anchoring), but form X should move along. So what I do is catch the LocationChanged event of the ParentForm of the control, and in that event I reposition form X. This works ok. However, now I'm in the situation that the control is placed on something that has no ParentForm. Question: how can I detect if a control's screen coordinates are changing? So the position of the control inside its parent remains the same, but the screen coordinates change because the parent is moved. Can I detect such movement?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      If the control is placed in a container besides a form, then recurse up through the containers to get to the form, like so:

      private Form GetContainerForm(Control c)
      {
      if (c == null) return null;
      if (c is Form) return (Form)c;
      else return GetContainerForm(c.Parent);
      }

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups