@Anonymous ,
this is the first form named as mainmaster , it has a panel named as mainpanel which will hold all the future forms inside it whether login or create voucher ,or delete voucher . it has a tablelayout on the right side .

its code behind file
public mainmaster()
{
InitializeComponent();
}
private void mainmaster_Load(object sender, EventArgs e)
{
RecreateCenterForm<TDlloading_error>();
}
private void RecreateCenterForm<T>() where T : Form, new()
{
// suggested by koz6.0
foreach (Form oldForm in Mainmasterpanel.Controls.OfType<Form>().ToArray())
{
using (oldForm)
{
oldForm.Close();
Mainmasterpanel.Controls.Remove(oldForm);
}
}
var newForm = new T
{
TopLevel = false,
// Visible = true
};
// Calculate the X and Y coordinates for centering the form
int x = (Mainmasterpanel.Width - newForm.Width) / 2;
int y = (Mainmasterpanel.Height - newForm.Height) / 2;
//// Set the location of the form
newForm.Location = new Point(x, y);
newForm.FormBorderStyle = FormBorderStyle.None;
newForm.StartPosition = FormStartPosition.CenterParent;
newForm.Anchor = AnchorStyles.None;
newForm.ControlBox = false;
newForm.ShowInTaskbar = false;
// newForm.BringToFront();
newForm.Show();
Mainmasterpanel.Controls.Add(newForm);
newForm.Focus(); // sets the focus to newly form
}
now when it loads , it opens a new form named as TDlloading_error .this form ie. TDlloading_error doesn't do anything as of now . Also note that its design has three panels but they don't do anything now but when the user presses enter , the user goes to login page .

code behing file
public TDlloading_error()
{
InitializeComponent();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Escape))
{
return true;
}
else if(keyData == (Keys.Enter))
{
RecreateCenterForm<login>();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void RecreateCenterForm<T>() where T : Form, new()
{
Panel P = this.Parent as Panel;
if (P != null)
{
foreach (Form oldForm in P.Controls.OfType<Form>().ToArray())
{
using (oldForm)
{
oldForm.Close();
P.Controls.Remove(oldForm);
}
}
var newForm = new T
{
TopLevel = false,
// Visible = true
};
// Calculate the X and Y coordinates for centering the form
int x = (P.Width - newForm.Width) / 2;
int y = (P.Height - newForm.Height) / 2;
// Set the location of the form
newForm.Location = new Point(x, y);
newForm.FormBorderStyle = FormBorderStyle.None;
newForm.StartPosition = FormStartPosition.CenterParent;
newForm.Anchor = AnchorStyles.None;
newForm.ControlBox = false;
newForm.ShowInTaskbar = false;
// newForm.BringToFront(); // no need as there is no previous form left to overlap the current form
P.Controls.Add(newForm);
newForm.Show();
newForm.Focus();
}
}
now here is the problem , till the user is not logged in , the user must not see the buttons in the tablelayout panel

yes you are correct these buttons should be hidden initially