Z-Order problem with usercontrols
Posted on 2013-12-29
Ok, here is my problem. It would seem like there is a simple solution but so far it has eluded me. I have a usercontrol which consists of a Developers Express (using their components) group box which is docked to all sides so it always fills the usercontrol. Inside of the groupbox there are a few buttons and a DE memoedit control docked to the bottom of the groupbox. I don't think the contents of the group box make a difference anyway. I am able to drag the control onto a form with no trouble, but I wanted to be able to place other controls inside the usercontrol at design time so I added the following above the usercontrol class definition:
This now allowed me to place other controls into my usercontrol at design time. When I move the usercontrol the controls move with it and they are clearly inside the usercontrol when you look at the document outline window, but here is the problem. When you place any control on the usercontrol it's z-order puts it behind the contents already in the usercontrol (the DE Group Box). If you select it in the document outline and then click on a handle and select move to front, the control places itself on top of everything else and all is well. That is until you save and reopen the form. When you reopen the form all of the controls you placed are once again behind the usercontrol contents. You would think when you saved the form the z-order would be saved but it does not work. The problem is there are going to be many of these usercontrols with a good deal of controls placed on top. Going from control to control and correcting them is not an option. I have even tried implementing a custom designer for a textbox control that I modified and is now a usercontrol. Here is the code:
public override void InitializeNewComponent(System.Collections.IDictionary defaultValues)
ILTextEdit ilTextEdit = (ILTextEdit) Component;
Hopefully this is the right way to access the component itself, I have very little experience with designers or the programming the visual studio IDE, though I have a decent amount of experience with C# applications. In any event when I drag this component unto the usercontrol now it is the top most control and it looks like the
problem is solved. Again, that is until you save the form and reopen it, just to find out the control is once again hidden.
Anyone have any idea how to correct this?