【C#】 画面コントロールの種別を見て処理を行う
C# で 画面コントロールの種別を見て処理を行う事があります。
ちょっと強引ですが、こんな感じでやりました。
他にもっといい手法があるはずなので
また更新します。
private void Data_Enabled(Boolean bbool)
{
foreach (Control c in MainPanel.Controls)
{
if (c.GetType().Equals(typeof(TextBox)))
{
if (kindNowValue == SyoriKind.UserCareLvl &&
c.Name == "txt_1")
{
c.Enabled = !bbool;
}
else if (c.Name != "txt_0")
{
c.Enabled = bbool;
}
}
else if (c.GetType().Equals(typeof(ComboBox)))
{
c.Enabled = bbool;
if(!bbool)
{
ComboBox tmp = (ComboBox)c;
tmp.SelectedIndex = -1;
}
}
else if (c.GetType().Equals(typeof(DateTimePicker)))
{
c.Enabled = bbool;
}
else if (c.GetType().Equals(typeof(Button)))
{
c.Enabled = bbool;
}
}
}