Custom control not visible inside group box, not positioned correctly

I have a custom control that I am adding programatically to a screen with controls inside a group box.  If I position it relative to a label inside the group box, the positioning is done relative to the form, not the group box, and when I reposition it so that it is "inside" the group box, it doesn't show, so I assume the group box is hiding it.  Here is the code I use to create and position it:

public partial class frmDetail : Form
        nullDateTimePicker ndtCalDate = new nullDateTimePicker();
        public frmDetail()

            this.ndtCalDate.Location = new System.Drawing.Point(this.lblNewCert.Location.X + 120, this.lblNewCert.Location.Y-5);
            this.ndtCalDate.Name = "ndtCalDate";
            this.ndtCalDate.Size = new System.Drawing.Size(200, 20);


How can I get the control to be properly positioned and visible inside the group box?
Who is Participating?
FrancineTaylorConnect With a Mentor Author Commented:
The reason I wanted to set it relative to the label is because the label is positioned with the editor, and I wanted the text box to be in a location relative to its label.

I tried setting it to an absolute position and it now works, not sure why it didn't before, but after poking about in the controls' properties for a while I figured out that I need to add in the location of the group box when figuring position;

this.ndtCalDate.Location = new System.Drawing.Point(groupBox1.Location.X + lblCalDate.Location.X + 120, groupBox1.Location.Y + lblCalDate.Location.Y - 5);
anarki_jimbelConnect With a Mentor Commented:
Not quite clear why you position it relative to a label. Just for a test try set location like 20,20 and see if this control is visible. Check if Visible property set to true. At the first glance the above code looks OK...
It looks like my post make you to think and find a solution?! :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.