1
我有一個從父窗體加載的子窗體。父窗體不是MDI父窗體。 我想要做到以下幾點:C#窗體控件樣式,通過樣式變化移除焦點
我想禁用具有焦點的控件,特別是按鈕和RadioButtons的虛線/虛線矩形。
目前我使用下面的代碼:
foreach (System.Windows.Forms.Control control in this.Controls)
{
// Prevent button(s) and RadioButtons getting focus
if (control is Button | control is RadioButton)
{
HelperFunctions.SetStyle(control, ControlStyles.Selectable, false);
}
}
哪裏我的SetStyle方法是
public static void SetStyle(System.Windows.Forms.Control control, ControlStyles styles,
bool newValue)
{
// .. set control styles for the form
object[] args = { styles, newValue };
typeof(System.Windows.Forms.Control).InvokeMember("SetStyle",
BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,
null, control, args);
}
不用說,這似乎並沒有工作。我不知道我在這裏失去了什麼。任何建議和/或建議將不勝感激。