I have the below method in a class, HUD.cs, that has helper methods. The below method is suppossed to check all controls TAG for "required" and highlight those it finds.
It works fine if I call it from a UserControl and the Control's to be Highlighted are not contained in a GroupBox but when they are the TAG does not seem to come across. Ideas?
Here's the method-->
public static void HighlightRequiredFields(Control container, Graphics graphics, Boolean isVisible)
{
var borderColor = Color.FromArgb(173, 216, 230);
const ButtonBorderStyle borderStyle = ButtonBorderStyle.Solid;
const int borderWidth = 3;
Rectangle rect = default(Rectangle);
foreach (Control control in container.Controls)
{
if (control.Tag is string && control.Tag.ToString() == "required")
{
rect = control.Bounds;
rect.Inflate(3, 3);
if (isVisible && control.Text.Equals(string.Empty))
{
ControlPaint.DrawBorder(graphics, rect,
borderColor,
borderWidth,
borderStyle,
borderColor,
borderWidth,
borderStyle,
borderColor,
borderWidth,
borderStyle,
borderColor,
borderWidth,
borderStyle);
}
else
{
ControlPaint.DrawBorder(graphics, rect, container.BackColor, ButtonBorderStyle.None);
}
}
if (control.HasChildren)
{
foreach (Control ctrl in control.Controls)
{
HighlightRequiredFields(ctrl, graphics, isVisible);
}
}
}
}