Custom control not visible inside group box, not positioned correctly

Posted on 2010-01-06
Last Modified: 2012-05-08
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?
Question by:FrancineTaylor
    LVL 29

    Assisted Solution

    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...
    LVL 1

    Accepted Solution

    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);
    LVL 29

    Expert Comment

    It looks like my post make you to think and find a solution?! :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now