private void numberPartTypes_TextChanged(object sender, EventArgs e) { mainForm MF = (mainForm)Application.OpenForms[GV.mainFormNumber]; //Gets to mainform level int initialY = 60; int startingX = 5; int maxNumberTypes = GV.maxNumberSubPanels; int currentY = initialY; int number; TextBox TB = sender as TextBox; Panel partsPanel = (Panel)TB.Parent; tbInt_TextChanged(sender, e); if (TB != null) { if (int.TryParse(TB.Text, out number)) //Checks if input is a valid integer { for (int i = partsPanel.Controls.Count - 1; i >= 0; i--) //This loop removes all panels, note it is independant of the integer check below { Control currentControl = partsPanel.Controls[i]; partsSubPanel panel = currentControl as partsSubPanel; if (panel != null) { partsPanel.Controls.Remove(panel); } } if (number > maxNumberTypes) { number = maxNumberTypes; TB.Text = maxNumberTypes.ToString(); } //If input number is to big, it is changed to the maximum number if (number == 0) { MF.missionPackage.editMissionGoal("partName", GV.defaultValue, "Part"); MF.missionPackage.editMissionGoal("partCount", GV.defaultValue, "Part"); MF.missionPackage.editMissionGoal("maxPartCount", GV.defaultValue, "Part"); } for (int i = 0; i < number; i++) //Places the proper amount of panels { partsSubPanel subPanel = new partsSubPanel(i); subPanel.Location = new Point(startingX, currentY); partsPanel.Controls.Add(subPanel); currentY += subPanel.Height + 5; } Panel goalDetailPanel = partsPanel.Parent as Panel; if (MF != null) { MF.changeGoalPanels(this); } MF.missionPackage.updateValue(partsPanel, "partSubPanel", "", "", number); } } }
private void numberPartTypes_TextChanged(object sender, EventArgs e) { int currentY = initialY; int number; TextBox tb = sender as TextBox; intChangeTextBox(tb); if (tb != null) { for (int i = this.Controls.Count - 1; i >= 0; i--) //This loop removes all panels, note it is independant of the integer check below { Control currentControl = this.Controls[i]; Panel panel = currentControl as Panel; if (panel != null) { this.Controls.Remove(panel); } } if (int.TryParse(tb.Text, out number)) //Checks if input is a valid integer { if (number > maxNumberTypes) { number = maxNumberTypes; tb.Text = maxNumberTypes.ToString(); } //If input number is to big, it is changed to the maximum number for (int i = 0; i < number; i++) //Places the propor amount of panels { partsSubPanel subPanel = new partsSubPanel(i); subPanel.Location = new Point(startingX, currentY); this.Controls.Add(subPanel); currentY += subPanel.Height + 5; } } Panel goalDetailPanel = this.Parent as Panel; mainForm MAINFORM = goalDetailPanel.Parent as mainForm; //Gets to mainform level if (MAINFORM != null) { MAINFORM.changeGoalPanels(this); } } }