Search code examples
c#winformsvb6windows-forms-designervb6-migration

winforms designer hand code bring to front


I'm converting some VB6 forms to C# and have created an utility which generates C# designer files from the VB6 source files. It's going well, but I've ran into some trouble with ordering.

I have an option button and an updown beside each other and the right side of the option button is slightly overlapping the updown. I tried resizing the option button, but no usable size seems to leave the caption visible.

I've considered changing the option button to have a transparent background, but unfortunately the solution isn't viable for all of my forms.

However, what I think would definitely work is bringing the updown to the front or sending the option button to the back, but I can't figure out how to do this from within the designer code only.

How can I bring controls to the front or send them to the back from the designer code? If anyone has a different solution for having the caption visible I'm open for suggestions. It must be done from within the designer code only, as that is what my tool generates.


Solution

  • The order in which controls are added to their parent determines the initial Z-order. The control added first will be in front of controls added later:

    this.Controls.Add(updownButton);
    this.Controls.Add(optionButton);