I realize there have been similar questions asked here before, but after scouring the site I've not found anything that addresses the specific issue I'm experiencing. I'm using C# in VS 2017. I have a base form and am trying to create/use an inherited form. The base form (frmDataEntry) contains several controls (a ListView, a ComboBox, two Labels, four Buttons, and a Panel. The inheriting form (frmEditRanch) adds six controls to the panel: three Labels, two Textboxes, and a PictureBox.
All of these controls appear and function as expected, except for the labels inside of the panel. Labels outside the panel are fine, as are the Textboxes and picturebox inside it; but the Label controls inside the panel do not show up. I'm stumped.
I've seen in other posts that the child form needs to create the controls in code, so I've tried that as well (creating the labels and adding them to the panel in code), but the result is no different.
Not sure how much code is needed to be helpful, but here is the initialization code that may be of some use.
BASE FORM:
public enum FormState { Idle, Adding, Editing }
public partial class frmDataEntry : Form
{
protected AgData db = new AgData();
protected Ranch ranch;
public const int vScrollBarWidth = 21;
public frmDataEntry()
{
InitializeComponent();
}
public frmDataEntry(int RanchID) : this()
{
ranch = db.GetRanch(RanchID);
}
protected void frmDataEntry_Load(object sender, EventArgs e)
{
if (DesignMode) return;
UpdateRanchNameComboBox();
cbRanchName.SelectedItem = ranch?.Name;
ResetDataFields();
SetFormControls(FormState.Idle);
CreateListViewHeaders();
UpdateRecordList();
}
...
CHILD FORM:
public partial class frmEditRanch : frmDataEntry
{
EditMode mode;
public frmEditRanch(EditMode editMode, int RanchID = 0) : base(RanchID)
{
InitializeComponent();
mode = editMode;
}
private void frmEditRanch_Load(object sender, EventArgs e)
{
AddDataControls();
}
protected override void AddDataControls()
{
Label lblName = new Label();
lblName.Font = new Font(this.Font.FontFamily, 12, FontStyle.Regular);
lblName.Text = "Name";
lblName.TextAlign = ContentAlignment.MiddleLeft;
lblName.AutoSize = false;
lblName.Size = new Size(45, 20);
lblName.Location = new Point(10, 23);
pnlDataControls.Controls.Add(lblName);
...
pnlDataControls.Refresh();
}
...