Yesterday I have implemented some validating events for controls in a groupbox located on a WinForm. I have set the AutoValidate property of the form to Disabled, I have set the CausesValidation property of the controls to true and implemented the Validating event of the controls. By calling the ValidateChildren() method of the form I force that validating events are executed. This was working all fine.
But after placing this groupbox on top of a picturebox and setting the picturebox as parent of the groupbox then validating events aren't executed anymore....
Below some demo code. Form is only containing a picturebox, groupbox, textbox and button.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
MessageBox.Show("Validating textbox");
e.Cancel = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (ValidateChildren())
MessageBox.Show("Validation not executed :-(");
else
MessageBox.Show("Validation executed :-)");
}
private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Parent = pictureBox1;
}
}