2016-10-13 6 views
-3

2つの解像度(1600x900と1280x720)のコンボボックスを持っています。私はそれらを "-screen-width XXXX -screen-height YYY"私が何かを試した瞬間に、私がコーディングで本当の初心者だから、 "保存して閉じる"ボートンを押すと、私が今までに作った最初のプログラムです。 基本的に私のプログラムは、それらを知らない人のための起動オプションを編集する簡単な方法になります これは私が "InitializeComponent();"私のコンボボックスremplaceの単語を.txtファイルにする

public Window1() 
    { 
     InitializeComponent(); 
     listResolution.Add("1600x900"); 
     listResolution.Add("1280x720"); 

     widthChoose = 1280; 
     heightChoose = 720; 
     windowed = true; 

     foreach (String item in listResolution) 
     { 
      ResolutionBox.Items.Add(item); 
     } 
    } 

これは

private void SaveClose_Click(object sender, RoutedEventArgs e) 
    { 
     if (Windowed.IsChecked == true) 
      windowed = true; 
     else 
      windowed = false; 

     string text = File.ReadAllText(@"Resources\arguments.txt"); 
     text = text.Replace("-screen-fullscreen 1", "-screen-fullscreen 0"); 
     File.WriteAllText("arguments.txt", text); 

     this.Close(); 

(テキストは置き換え動作しません)私は、「保存して閉じる」bouttonのために持っているものであり、私は私のコンボボックス

private void ResolutionBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 

    } 
のためのイベントを持っていません

私の "arguments.txt"の内容

-screen-fullscreen 0 -screen幅1600 -screen、高さ900

+0

なぜ投票が下りますか? :/ – Francefire

+0

arguments.txtの内容と解像度ごとの出力はありません。この質問に答える方法はありません。 – Martheen

+0

ありがとうございました。ありがとうございました。 – Francefire

答えて

0

File.WriteAllText("arguments.txt", text); 

は、これらを追加する前に:

まず、我々は選択した解像度(そこlistResolutionの目的がわからない)

を取ります
var selectedResolution = ResolutionBox.SelectedItem.ToString(); 

幅と高さに分割

var split = selectedResolution.Split('x'); 
widthChoose = split[0]; 
heightChoose = split[1]; 

その後、新しい値で1600 & 900を置き換える:

text = text.Replace("1600",widthChoose) 

は、高さを続行します。

+0

'split [0];'がエラーとして表示されます。代わりに入れても大丈夫ですか? 'widthChoose = Int32.Parse(split [0]);' – Francefire

+0

おっと、私はあなたの幅と高さが整数であるのを忘れました。 – Martheen

+0

ありがとうたくさんの男<3 – Francefire

関連する問題