I’m pretty new to C#-programming, so I’m sorry if the question may sound too easy for you:
I am programming a desktop-software for my workouts and I have a mainform, in which I have a page for “short-term planning” (pg_KurzfristigeTrainingplanung). From that page I call another form (frm_KurzfristigeTrainingsplanung), where I enter the dates and the workouts I want to train those days. With a button I want to “feed back” those entries to that very same page “short-term planning” (pg_KurzfristigeTrainingplanung) from which I called the form for the planning.
The values I entered in the form shall then be entered into the page and also “stay” there until I change them again (Aswell after closing the entire program).
Now my question: How can I initiate or tell the program to refer back to that page?
Please find my code-snippet below.
Thanks for your help in advance and I hope my question is somehow clear for you.
Have a great evening,
Dominique
private void btnEintragen_Click(object sender, EventArgs e)
{
pg_KurzfristigeTrainingsplanung pgKF = pg_KurzfristigeTrainingsplanung;
// Schleife von 1 bis 7
for (int i = 1; i <= 7; i++)
{
if (i == 1)
{
// Spezialfall für i = 1: DateTimePicker und TextBox
DateTimePicker dtpDatum1 = (DateTimePicker)this.Controls.Find("dtpDatum1", true).FirstOrDefault();
Label lblDatum1 = (Label)pgKF.Controls.Find("lblDatum1", true).FirstOrDefault();
if (dtpDatum1 != null) // && lblDatum1 != null
{
lblDatum1.Text = dtpDatum1.Value.ToString("dd.MM.yyyy");
}
}
else
{
// Standardfall für i = 2 bis 7: Labels
Label lblDatumFormKF = (Label)this.Controls.Find("lblDatum" + i, true).FirstOrDefault();
Label lblTrainingFormKF = (Label)this.Controls.Find("lblTraining" + i, true).FirstOrDefault();
Label lblFocusFormKF = (Label)this.Controls.Find("lblFocus" + i, true).FirstOrDefault();
Label lblDatumpgKF = (Label)pgKF.Controls.Find("lblDatum" + i, true).FirstOrDefault();
Label lblTrainingpgKF = (Label)pgKF.Controls.Find("lblTraining" + i, true).FirstOrDefault();
Label lblFocuspgKF = (Label)pgKF.Controls.Find("lblFocus" + i, true).FirstOrDefault();
// Falls die Controls gefunden wurden, deren Text übertragen
if (lblDatumFormKF != null && lblDatumpgKF != null)
{
lblDatumpgKF.Text = lblDatumFormKF.Text;
}
if (lblTrainingFormKF != null && lblTrainingpgKF != null)
{
lblTrainingpgKF.Text = lblTrainingFormKF.Text;
}
if (lblFocusFormKF != null && lblFocuspgKF != null)
{
lblFocuspgKF.Text = lblFocusFormKF.Text;
}
}
}
//Schliesst die Form nach erfolgreichem Eintragen der Daten
this.Close();
}
I tried to feed back the values from the “planning-form” back to the earlier page.
I expected the values to show up, but the values did not show up on the page “pg_KurzfristigeTrainingsplanung”
Dominique Müller is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.