Hello,
I am creating WPF app in C# that creates a mathematical tasks for kids(addition, subtraction etc.). In one User Controller I have a button "Begin", which loads another UC and in that UC I have 10 tasks, beside every task I have Text Box for user to input answer and I have button "Confirm" (all of this is dynamically created), to be able to make a list of user answers when the button is clicked. But now, I have a problem with empty Text Boxes.
I want, when the button "Confirm" is clicked, to check if there are an empty Text Box-es, and if there is/are, I want Label/s to appear with some text beside that empty box/es. As soon as user start typing in that or those particular text box(es) I want that label to dissapear.
What I have tried:
This is where I create tasks and Text Boxes:
public void CreateTasksVisually(UCFirstLevelAddition userControl, List<string> additionTasksList)
{
int x = 350, y = 200;
for (int i = 0; i < 10; i++)
{
userControl.Controls.Add(new Label
{
Text = additionTasksList[i],
Height = 40,
Width = 100,
Name = "additionTaskLabel" + i,
BackColor = Color.Transparent,
Location = new Point(x, y + 15)
});
userControl.Controls.Add(new TextBox
{
Name = "container" + i.ToString(),
Text = "",
Height = 20,
Width = 50,
BackColor = Color.White,
Location = new Point(x + 120, y + 15)
});
y = y + 60;
}
}
This is where I create a button "Confirm":
public Button CreateSubmitBtnVisually(UCFirstLevelAddition userControl)
{
int x = 350, y = 200;
Button submitBtn = new Button();
submitBtn.Name = "btnSubmit";
submitBtn.Text = "Potvrdi";
submitBtn.Size = new Size(100, 40);
submitBtn.Location = new Point(350, 829);
submitBtn.Click += new EventHandler(userControl.submitBtn_Click);
userControl.Controls.Add(submitBtn);
return submitBtn;
}
And this is where I try to check if anyone of the Text Box-es is empty:
public void CreateEmptyContainerLabels(UCFirstLevelAddition userControl)
{
int x = 550, y = 180;
Label message = new Label();
foreach (Control c in userControl.Controls)
{
if (c is TextBox)
{
TextBox container = c as TextBox;
if (container.Text.Length == 0)
{
message.Text = string.Format("Ne sme biti prazno!");
message.Width = 400;
message.ForeColor = Color.Red;
message.Font = new Font("Century Gothic", 16, FontStyle.Bold);
message.Location = new Point(x, y + 40);
}
userControl.Controls.Add(message);
y = y + 60;
}
}
}
But this check is not doing what I want. Can you help me with this?
Thank's in advance.