の種類:リミット私はこのようなコードを持って、基本クラスのパラメータ
public static void ToUpperCase(params Control[] controls)
{
foreach (Control oControl in controls)
{
if (oControl is TextBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
TextBox txtControl = sndr as TextBox;
int pos = txtControl.SelectionStart;
txtControl.Text = txtControl.Text.ToUpper();
txtControl.SelectionStart = pos;
};
}
else if (oControl is ComboBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
ComboBox cmbControl = sndr as ComboBox;
int pos = cmbControl.SelectionStart;
cmbControl.Text = cmbControl.Text.ToUpper();
cmbControl.SelectionStart = pos;
};
}
else throw new NotImplementedException(oControl.GetType().DeclaringType.ToString() + " is not allowed.");
}
}
私だけTextBox
とComboBox
タイプを受け入れるようにparams Control[] controls
を制限したいです。
私のコードはC#、フレームワーク4、VS2010Proでビルドされています。プロジェクトはWinFormsにあります。
助けてください。前もって感謝します。
1つまたは他のものと同様に、TextBoxの配列またはComboBoxの配列になりますか?または、それはTextBoxとComboBoxの配列である可能性がありますか? – Zenexer