сделаны диалоговые окна сохранения и открытия файла

This commit is contained in:
Александр 2026-04-05 15:35:46 +03:00
parent a0b9730877
commit 5752f28a68
4 changed files with 90 additions and 10 deletions

41
result.Designer.cs generated
View File

@ -1,4 +1,4 @@
namespace тест namespace тест
{ {
partial class result partial class result
{ {
@ -30,6 +30,9 @@
{ {
this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBox1 // textBox1
@ -42,11 +45,42 @@
this.textBox1.TabIndex = 0; this.textBox1.TabIndex = 0;
this.textBox1.FontChanged += new System.EventHandler(this.textBox1_FontChanged); this.textBox1.FontChanged += new System.EventHandler(this.textBox1_FontChanged);
// //
// saveFileDialog1
//
this.saveFileDialog1.Filter = "Текстовые файлы (*.txt)|*.txt";
this.saveFileDialog1.Title = "Сохранить результат";
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 281);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(355, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Сохранить результат";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(13, 310);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(355, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Загрузить результат";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// result // result
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(380, 450);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1); this.Controls.Add(this.textBox1);
this.Name = "result"; this.Name = "result";
this.Text = "result"; this.Text = "result";
@ -61,5 +95,8 @@
private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
} }
} }

View File

@ -1,8 +1,10 @@
using System; using Microsoft.Win32;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -25,8 +27,25 @@ namespace тест
} }
int sum; int sum;
int vopros1, vopros2, vopros3, vopros4, vopros5;
public result(string f, string l, string g, string c, int s) private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.Cancel) { return; }
textBox1.Text = File.ReadAllText(openFileDialog1.FileName);
}
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.FileName = "Результат " + lname + " " + fname + ".txt"; // имя по умолчанию
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(saveFileDialog1.FileName, textBox1.Text);
}
}
public result(string f, string l, string g, string c, int s, int v1, int v2, int v3, int v4, int v5)
{ {
InitializeComponent(); InitializeComponent();
@ -35,6 +54,13 @@ namespace тест
group = g; group = g;
course = c; course = c;
sum = s; sum = s;
vopros1 = v1;
vopros2 = v2;
vopros3 = v3;
vopros4 = v4;
vopros5 = v5;
} }
private void result_Shown(object sender, EventArgs e) private void result_Shown(object sender, EventArgs e)
@ -44,7 +70,21 @@ namespace тест
"Имя: " + fname + Environment.NewLine + "Имя: " + fname + Environment.NewLine +
"Группа: " + group + Environment.NewLine + "Группа: " + group + Environment.NewLine +
"Курс: " + course + Environment.NewLine + "Курс: " + course + Environment.NewLine +
"Количество баллов: " + Convert.ToString(sum) + Environment.NewLine; "Количество баллов: " + Convert.ToString(sum) + Environment.NewLine +
"******************" + Environment.NewLine +
"Вопрос 1: " + correct(vopros1) + Environment.NewLine +
"Вопрос 2: " + correct(vopros2) + Environment.NewLine +
"Вопрос 3: " + correct(vopros3) + Environment.NewLine +
"Вопрос 4: " + correct(vopros4) + Environment.NewLine +
"Вопрос 5: " + correct(vopros5);
}
private string correct(int a)
{
if (a == 0) { return "Неверно"; }
else if (a == 1) { return "Верно"; }
return "Неопределенно";
} }
} }
} }

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<root> <root>
<!-- <!--
Microsoft ResX Schema Microsoft ResX Schema
@ -120,4 +120,7 @@
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>152, 17</value>
</metadata>
</root> </root>

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -375,7 +375,7 @@ namespace тест
{ {
sum = v1 + v2 + v3 + v4 + v5; sum = v1 + v2 + v3 + v4 + v5;
result result = new result(fname, lname, group, course, sum); result result = new result(fname, lname, group, course, sum, v1, v2, v3, v4, v5);
result.Show(); result.Show();
this.Hide(); this.Hide();
} }