(tabControlレイアウトに)多くのテキストボックスがあるフォームがあります。すべてのテキストボックスで右クリック機能を無効にしています。以下のコードを与えることによって:
txtAmountChildPlans.ContextMenu = new ContextMenu();
txtCityHome.ContextMenu = new ContextMenu();
txtCityPersonal.ContextMenu = new ContextMenu();
txtCityRetirement.ContextMenu = new ContextMenu();
txtEmailCar.ContextMenu = new ContextMenu();
txtEmailCarIns.ContextMenu = new ContextMenu();
txtEmailHome.ContextMenu = new ContextMenu();
txtEmailOp.ContextMenu = new ContextMenu();
txtEmailPersonal.ContextMenu = new ContextMenu();
txtEmailSenior.ContextMenu = new ContextMenu();
txtEmailTwoIns.ContextMenu = new ContextMenu();
txtFullNamePersonal.ContextMenu = new ContextMenu();
txtManufacturerCar.ContextMenu = new ContextMenu();
txtMobileCar.ContextMenu = new ContextMenu();
txtMobileCarIns.ContextMenu = new ContextMenu();
txtMobileHome.ContextMenu = new ContextMenu();
txtMobileNoRetirement.ContextMenu = new ContextMenu();
txtMobileOp.ContextMenu = new ContextMenu();
txtMobilePersonal.ContextMenu = new ContextMenu();
txtMobileSenior.ContextMenu = new ContextMenu();
txtMobileTwoIns.ContextMenu = new ContextMenu();
txtModelCar.ContextMenu = new ContextMenu();
txtMonthlySalaryCar.ContextMenu = new ContextMenu();
txtNameHome.ContextMenu = new ContextMenu();
txtNameRetirement.ContextMenu = new ContextMenu();
txtPensionRetirement.ContextMenu = new ContextMenu();
txtRegCarIns.ContextMenu = new ContextMenu();
txtRegTwoIns.ContextMenu = new ContextMenu();
編集:
foreach (var textbox in this.Controls.OfType<TextBox>())
{
textbox.ContextMenu = new ContextMenu();
}
foreach (var textbox in this.tabCarInsurance.Controls.OfType<TextBox>())
{
textbox.ContextMenu = new ContextMenu();
}
foreach (var textbox in this.tabHealth.Controls.OfType<TextBox>())
{
textbox.ContextMenu = new ContextMenu();
}
foreach (var textbox in this.tabHomeLoans.Controls.OfType<TextBox>())
{
textbox.ContextMenu = new ContextMenu();
}
foreach (var textbox in this.tabRetirement.Controls.OfType<TextBox>())
{
textbox.ContextMenu = new ContextMenu();
}
とにかくこれをsigle関数で書くことはありますか?以下のコード?
これは私にはよく見えません。cssのようにc#ですべてのテキストボックスに同じプロパティを与える方法はありますか?