2014-12-13 32 views
-3

在Visual Studio設計器(我使用2012)沒有辦法將ApplicationSettings機制鏈接到SelectedIndex屬性(僅文本)。c#如何鏈接組合框SelectedIndex到ApplicationSettings

可以使用哪種解決方法代替?


對不起,如果我的問題是針對StackOverflow規則。我搜索了我的問題,發現沒有確切的答案。

我不知道如何自定義代碼ApplicationSettings。我始終在設計模式中使用此功能 - 鏈接我的文本框的文本屬性,然後使用Properties.Settings.Default.Save()保存並在Form_Load上使用Properties.Settings.Default.SomeName來加載保存的值。 除此之外的一切都是通過VisualStudio完成的,我不知道爲了我的需要改變它的行爲。

我確信這個問題將開始編程人員

+0

確定有一種方法和解決方法...它被稱爲編程。你必須自己寫。 – t3chb0t 2014-12-13 09:06:56

+0

你能舉一個簡單的例子或至少一些鏈接嗎? – BorisE 2014-12-13 09:13:28

+0

不,你向我們展示你到目前爲止所做的,然後我們會提供幫助。 – matsjoyce 2014-12-13 10:59:05

回答

1

寫一些代碼是有用的,它是用設計師的方便,除此之外,設計師產生太多的代碼,你不明白。

enter image description here

在Visual Studio Edit Settings,添加一個名爲 「SelectedIndex的」 屬性,將其類型爲int和範圍爲User,值爲0(這意味着第一個項目被選中)。您可以在代碼中訪問此屬性:

public Form1() 
{ 
    InitializeComponent(); 
    comboxBox1.SelectedIndex = Properties.Settings.Default.SelectedIndex; 
    this.Closing += Form1_Closing; 
} 

void Form1_Closing(object sender, CancelEventArgs e) 
{ 
    Properties.Settings.Default.SelectedIndex = comboxBox1.SelectedIndex; 
    Properties.Settings.Default.Save(); 
}