namespace TempW
{
partial class Form2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtEntry = new System.Windows.Forms.TextBox();
this.btnAdd = new System.Windows.Forms.Button();
this.btnReload = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(33, 175);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(33, 206);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 13);
this.label2.TabIndex = 1;
this.label2.Text = "label2";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(33, 238);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 13);
this.label3.TabIndex = 2;
this.label3.Text = "label3";
//
// txtEntry
//
this.txtEntry.Location = new System.Drawing.Point(36, 12);
this.txtEntry.Name = "txtEntry";
this.txtEntry.Size = new System.Drawing.Size(100, 20);
this.txtEntry.TabIndex = 3;
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(184, 9);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 4;
this.btnAdd.Text = "Добавить";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// btnReload
//
this.btnReload.Location = new System.Drawing.Point(184, 165);
this.btnReload.Name = "btnReload";
this.btnReload.Size = new System.Drawing.Size(75, 23);
this.btnReload.TabIndex = 5;
this.btnReload.Text = "Перечитать";
this.btnReload.UseVisualStyleBackColor = true;
this.btnReload.Click += new System.EventHandler(this.btnReload_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.btnReload);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtEntry);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form2";
this.Text = "Form2";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtEntry;
private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Button btnReload;
}
}
using System;
using System.Windows.Forms;
using System.IO;
namespace TempW
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
ReloadPoints();
}
//Читаем первую, вторую и последнюю строку
private void ReloadPoints()
{
try//Если файл еще не создан
{
StreamReader SR = new StreamReader(Application.StartupPath + "\\points.txt");
label1.Text = SR.ReadLine();
label2.Text = SR.ReadLine();
String Cur = null, Last = null;
while ((Cur = SR.ReadLine()) != null)
Last = Cur;
label3.Text = Last;
SR.Close();
}
catch (Exception) { }
}
//Дописываем строку
private void btnAdd_Click(object sender, EventArgs e)
{
StreamWriter SW=new StreamWriter(Application.StartupPath + "\\points.txt", true);
SW.WriteLine(txtEntry.Text);
SW.Close();
}
private void btnReload_Click(object sender, EventArgs e)
{
ReloadPoints();
}
}
}
Sub load()
On Error GoTo lab
Open "list.dat" For Input As #2
For mm = 0 To 4
Line Input #2, data
frmBest.txt.Item(mm).Text = data
Line Input #2, data
frmBest.Label1.Item(mm).Caption = data
Next mm
Close #2
lab:
End Sub
Sub save()
On Error Resume Next
SetAttr "list.dat", vbNormal
Open "list.dat" For Output As #1
For mm = 0 To 4
Print #1, frmBest.txt.Item(mm).Text
Print #1, frmBest.Label1.Item(mm).Caption
Next mm
Close #1
SetAttr "list.dat", vbHidden + vbReadOnly
End Sub
Sub load() 'Процедура чтения сохраненных данных
On Error GoTo lab 'При ошибке переходим к метке lab, пока что там ничего нет, но можно проверять код ошибки. Вобще эта строчка нужна для случая когда файл не существует.
Open "list.dat" For Input As #2 'Открываем файл для чтения под номером 2.
For mm = 0 To 4 ' У меня в программе была пятерка лучших 0, 1, 2, 3, 4 итого 5.
Line Input #2, data 'Читаем строку с файла номер 2 в переменную data
frmBest.txt.Item(mm).Text = data 'Форма где расположены игроки.Элемент текстовое поле.Текс в этом поле. Ложим туда прочитанную строку. У меня это были игроки.
Line Input #2, data 'Читаем следующую строку
frmBest.Label1.Item(mm).Caption = data 'Форма где расположены игроки.Элемент лабел(метка по русски).Заголовок. Ложим туда следующуу строку - у меня это очки.
Next mm 'Повторяем 5 раз.
Close #2 'Обязательно закрываем файл
lab:
'Тут можно написать код проверки кода ошибки
End Sub
Sub save() 'Процедура записи(сохранения) данных в файл
On Error Resume Next 'Все ошибки игнорируем
SetAttr "list.dat", vbNormal 'Если файл уже есть, то у него стоит атрибут "Только для чтения". А нам надо в него записывать данные, поэтому снимаем все атрибуты.
Open "list.dat" For Output As #1 'Открываем файл для ввода в него данных(вывода из программы) под номером 1.
For mm = 0 To 4 'Аналогично процедуре загрузке
Print #1, frmBest.txt.Item(mm).Text 'Записываем в файл строку
Print #1, frmBest.Label1.Item(mm).Caption 'Записываем в файл строку
Next mm
Close #1 ' Закрываем файл
SetAttr "list.dat", vbHidden + vbReadOnly 'Ставим атрибуты на файл, чтобы кто попало не мог изменить файл.
End Sub
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.