4-Описание программы final (1061387), страница 4
Текст из файла (страница 4)
}
private void акваToolStripMenuItem_Click_1(object sender, EventArgs e)
{
UnCheckMenuItems();
акваToolStripMenuItem.Checked = true;
Cbo_Rtb_Edit_ColorSet(System.Drawing.Color.LightBlue);
Cmd_Cbo_FlatStyleSet(FlatStyle.Flat, FlatStyle.Flat);
Label_GroupBox_MenuItem_Cmd_ForeColorSet(System.Drawing.Color.Gold);
Cmd_FlatAppearanceBorderColorSet(System.Drawing.Color.Gold);
Cmd_FlatAppearanceMouseOverBackColorSet(System.Drawing.Color.RoyalBlue);
this.BackgroundImage = PCComm.Properties.Resources.bg;
this.Visible = false;
this.Refresh();
this.Visible = true;
}
private void золотойToolStripMenuItem_Click_1(object sender, EventArgs e)
{
UnCheckMenuItems();
золотойToolStripMenuItem.Checked = true;
Cbo_Rtb_Edit_ColorSet(System.Drawing.Color.PapayaWhip);
Cmd_Cbo_FlatStyleSet(FlatStyle.Flat, FlatStyle.Flat);
Label_GroupBox_MenuItem_Cmd_ForeColorSet(System.Drawing.Color.Black);
Cmd_FlatAppearanceBorderColorSet(System.Drawing.Color.Black);
Cmd_FlatAppearanceMouseOverBackColorSet(System.Drawing.Color.Orange);
this.BackgroundImage = PCComm.Properties.Resources.bg1;
this.Refresh();
}
private void стандартныйToolStripMenuItem_Click_1(object sender, EventArgs e)
{
UnCheckMenuItems();
стандартныйToolStripMenuItem.Checked = true;
Cbo_Rtb_Edit_ColorSet(System.Drawing.Color.White);
Cmd_Cbo_FlatStyleSet(FlatStyle.Standard, FlatStyle.Standard);
Label_GroupBox_MenuItem_Cmd_ForeColorSet(System.Drawing.Color.Black);
this.BackColor = System.Drawing.Color.LightGray;
this.BackgroundImage = null;
this.Refresh();
}
private void UnCheckMenuItems()
{
акваToolStripMenuItem.Checked = false;
золотойToolStripMenuItem.Checked = false;
стандартныйToolStripMenuItem.Checked = false;
}
#endregion
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.Show();
}
private void button3_Click(object sender, EventArgs e)
{
mytimer2.Stop();
}
private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
{
// запись текущей истории в тесктовый файл
string path = Application.StartupPath + @"\" + user1 + "_" + user2 + ".txt";
StreamWriter sw = new StreamWriter(path, true, Encoding.Default);
for (int i = 0; i < rtbDisplay.Lines.Length; i++)
sw.WriteLine(rtbDisplay.Lines[i]);
sw.Close();
}
private void открытьФайлИсторииToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Тесктовые файлы (*.txt)|*.txt";
openFileDialog1.InitialDirectory = Application.StartupPath;
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, EventArgs e)
{
Form3 f = new Form3();
f.filepath = openFileDialog1.FileName; // передача в форму 3 пути к выбранному файлу истории
f.Text = "История ( " + openFileDialog1.SafeFileName.Replace(".txt", "") + " )";
f.Show();
}
private void frmMain_Shown(object sender, EventArgs e)
{
f.Show();
}
}
}
Form3.cs (форма «История »)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PCComm
{
public partial class Form3 : Form
{
public string filepath; // путь к файлу истории
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
// открытие файла истории в окне ричтекстбокса
StreamReader sr = new StreamReader (filepath, Encoding.Default);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
}
private void копироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
Clipboard.Clear();
Clipboard.SetText(richTextBox1.SelectedText);
}
private void выделитьВсеToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.SelectAll();
}
}
}
Form4.cs ( форма ввода имен)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PCComm
{
public partial class Form4 : Form
{
public string user1;
public string user2;
private string settings_file = Application.StartupPath + @"\settings.txt";
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
user1 = textBox1.Text;
user2 = textBox2.Text;
using (StreamWriter file = new StreamWriter(settings_file))
{
file.WriteLine(user1);
file.WriteLine(user2);
}
Form4.ActiveForm.Close();
}
private void Form4_Shown(object sender, EventArgs e)
{
if (File.Exists(settings_file))
{
StreamReader sr = new StreamReader(settings_file);
textBox1.Text = sr.ReadLine();
textBox2.Text = sr.ReadLine();
sr.Close();
this.Refresh();
}
}
}
}















