none
Automatically change to a new parent when control is moved over it RRS feed

  • Question

  • I will try to explain this as best as I can.

    I made my own custom groupBox Control.  How do I make it so when I add a button or anything to it that it will be on top so it's visible and move when I move the control groupBox arround?  I'm sure it has to do with parents and children.  I have a way to do it in my head by getting child at point, but that may interfere with other controls such as when a button by accident gets added over another button.

    Some notes.  I am also using a custom form control that I created.

    • Moved by CoolDadTx Friday, May 31, 2013 2:07 PM Winforms related
    Friday, May 31, 2013 6:05 AM

Answers

All replies

  • Hi M,

    are you referring to desktop applications (i.e. WinForms) or some other part of the .NET library? Yes, you are right that this has to do with childs and parents, but we'd need some more information about what you are trying to accomplish.

    For instance, are you referring to adding the button(s) at design-time in the Visual Studio form designer, or do you want to let the user add new controls at runtime?

    Thanks!


    Regards,

    Jani Järvinen [C# MVP]
    Vantaa, Finland
    Work: jani.jarvinen@removethis.moonsoft.fi
    Home: janij@removethis.dystopia.fi
    http://www.saunalahti.fi/janij/

    Friday, May 31, 2013 7:14 AM
  • I think it's more related to "Bring to Front" and "Send to Back".

    Faisal Ahmed Farooqui —————————— If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, May 31, 2013 11:16 AM
  • Hi Faisal,

    it could be a z-order thing as well, but as far as I can tell, the original poster referred that the button should move along with the group box.

    So, if we were talking about WinForms development (my assumption), then the button should be a child of the groupbox, if moving the groupbox around should move the button, too.

    But I guess we need to wait for furtner information from the original poster.


    Regards,

    Jani Järvinen [C# MVP]
    Vantaa, Finland
    Work: jani.jarvinen@removethis.moonsoft.fi
    Home: janij@removethis.dystopia.fi
    http://www.saunalahti.fi/janij/

    Friday, May 31, 2013 12:32 PM
  • right, I think "bing to Front" and "Send to back" does the same in code-behind file.

    And ofcourse, button will move with its parent (in this case groupbox).

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.sendtoback.aspx


    Faisal Ahmed Farooqui —————————— If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Friday, May 31, 2013 1:33 PM
  • You can Inherit your control from ContainerControl

    What is the base class you used for Building your Control?


    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming




    Friday, May 31, 2013 1:53 PM
  • Sorry guys.  I forgot to mention that it is WinForms.  I'm inheriting Control.  As for when the control is getting added.  It's at design time from the Visual Studio Designer.

    Solved.  Just inherited ContainerControl

    • Edited by Metroidn1f Friday, May 31, 2013 8:47 PM Solved!
    Friday, May 31, 2013 6:18 PM
  • Change your base class to ContainerControl. That should make it work.

    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

    Friday, May 31, 2013 7:45 PM