2
我在這個主題中發現了很多問題,但不是這一個:我正在使用c#應用程序設置,但將每個設置保存在新行中變得非常難看。我試圖挽救這個用下面的代碼:爲什麼我在這裏得到''System.Windows.Forms.Control'沒有包含「Checked'...」的定義?
for (int j = 0; j < settingsTabControl.SelectedTab.Controls.Count; j++)
{
string currItemName = settingsTabControl.SelectedTab.Controls[j].Name;
if (currItemName.Substring(0, 7) == "savable" && currItemName == currOptionName)
{
if (savableRunAsAdmin.HasProperty("Text"))
{
settingsTabControl.SelectedTab.Controls[j].Text = currOptionValue;
}
else if (savableRunAsAdmin.HasProperty("Checked"))
{
settingsTabControl.SelectedTab.Controls[j].Checked = Convert.ToBoolean(currOptionValue);
}
}
}
public static bool HasProperty(this object objectToCheck, string methodName)
{
var type = objectToCheck.GetType();
return type.GetProperty(methodName) != null;
}
但它說,這
'System.Windows.Forms.Control' does not contain a definition for 'Checked' and no extension method 'Checked' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?)
我可以動態地保存設置,或者我必須保存每個設置一個接一個?
演員到'CheckBox'或'RadioButton'。 –