0
我在具有輔助方法的類HUD.cs中有以下方法。下面的方法是suppossed檢查所有控件TAG爲「必需」,並突出顯示它找到的。控件不轉換爲靜態方法的標記屬性
它工作正常,如果我從UserControl調用它,並且要顯示的控件不包含在GroupBox中,但是當它們是TAG似乎沒有遇到。想法?
這裏的方法 - >
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);
}
}
}
}