[英]Make my combobox replace words in .txt file
I have a ComboBox with two resolution (1600x900 and 1280x720), I want them to replace "-screen-width XXXX -screen-height YYY" by the resolution chosen , in my TXT file when I press the "Save and Close" boutton, for the moment I've tried anything because I'm a real beginner at coding, it's my first Program I ever made.我有一个具有两种分辨率(1600x900 和 1280x720)的 ComboBox,我希望它们在我的 TXT 文件中按“保存并关闭”按钮时,将“-screen-width XXXX -screen-height YYY”替换为所选分辨率,目前我已经尝试了任何东西,因为我是一个真正的编码初学者,这是我制作的第一个程序。 Basically, my program will be an easy way to edit launch options for guys who don't know them This is what I have in "InitializeComponent();"基本上,我的程序将是一种简单的方法来为不认识他们的人编辑启动选项这就是我在“InitializeComponent();”中的内容
public Window1()
{
InitializeComponent();
listResolution.Add("1600x900");
listResolution.Add("1280x720");
widthChoose = 1280;
heightChoose = 720;
windowed = true;
foreach (String item in listResolution)
{
ResolutionBox.Items.Add(item);
}
}
This is what I have for my "Save and Close" boutton (The text replace doesn't work)这是我的“保存并关闭”按钮(文本替换不起作用)
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();
And I have no event for my comboBox我的 comboBox 没有活动
private void ResolutionBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
Content of my "arguments.txt"我的“arguments.txt”的内容
-screen-fullscreen 0 -screen-width 1600 -screen-height 900 -screen-fullscreen 0 -screen-width 1600 -screen-height 900
Right before就在之前
File.WriteAllText("arguments.txt", text);
Add these :添加这些:
First we take the selected resolution (not sure the purpose of listResolution there)首先我们采用选定的分辨率(不确定那里的 listResolution 的目的)
var selectedResolution = ResolutionBox.SelectedItem.ToString();
split it to width and height将其拆分为宽度和高度
var split = selectedResolution.Split('x');
widthChoose = split[0];
heightChoose = split[1];
then replace 1600 & 900 with the new values :然后用新值替换 1600 & 900 :
text = text.Replace("1600",widthChoose)
continue with height.继续高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.