Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

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()
        {
            InitializeComponent();
            this.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.groupBox1.Controls.Add(this.ndtCalDate);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();

            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);
            this.ndtCalDate.BringToFront();

            this.Controls.Add(this.ndtCalDate);
            this.ResumeLayout(false);
            this.PerformLayout();
    }
}

How can I get the control to be properly positioned and visible inside the group box?
0
FrancineTaylor
Asked:
FrancineTaylor
  • 2
2 Solutions
 
anarki_jimbelCommented:
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...
0
 
FrancineTaylorAuthor 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);
0
 
anarki_jimbelCommented:
It looks like my post make you to think and find a solution?! :)
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now