yardie, вот тоже могу поделиться, правда переводит с русского на украинский и обратно:
Form1.cs
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
| #region Переменные.
ToolTip toolTip = new ToolTip();
List<string> textToolTip = new List<string>()
{
"Доавить в словарь.", "Просмотр словаря.", "Перевести слово.", "Выбор языка перевода."
};
List<string> ruLang = new List<string>();
List<string> ukrLang = new List<string>();
#endregion
#region Инициализация программы.
public DictionaryForm()
{
InitializeComponent();
}
private void DictionaryForm_Load(object sender, EventArgs e)
{
langComboBox.SelectedIndex = 0;
ruLang.AddRange(File.ReadAllLines("ru.txt"));
ukrLang.AddRange(File.ReadAllLines("ukr.txt"));
}
#endregion
#region Отображаем всплывающую подсказку.
private void AddButton_MouseEnter(object sender, EventArgs e)
{
toolTip.Active = true;
if (sender == AddButton)
{
toolTip.Show(textToolTip[0], AddButton);
return;
}
if (sender == viewDictionaryButton)
{
toolTip.Show(textToolTip[1], viewDictionaryButton);
return;
}
if (sender == translateButton)
{
toolTip.Show(textToolTip[2], translateButton);
return;
}
}
private void MouseLeave_Button(object sender, EventArgs e)
{
toolTip.Active = false;
}
private void langComboBox_MouseEnter(object sender, EventArgs e)
{
toolTip.Active = true;
toolTip.Show(textToolTip[3], langComboBox);
}
private void langComboBox_MouseLeave(object sender, EventArgs e)
{
toolTip.Active = false;
}
#endregion
#region Добавляем слово в словарь.
private void AddButton_Click(object sender, EventArgs e)
{
NewWord newWord = new NewWord();
if (newWord.AddWord() == DialogResult.OK & newWord.wordTextBox.Text != "" & newWord.translateTextBox.Text != "")
{
ruLang.Add(newWord.wordTextBox.Text);
ukrLang.Add(newWord.translateTextBox.Text);
File.WriteAllLines("ru.txt", ruLang);
File.WriteAllLines("ukr.txt", ukrLang);
}
}
#endregion
#region Отображаем словарь.
private void viewDictionaryButton_Click(object sender, EventArgs e)
{
ViewDictionary viewDictionary = new ViewDictionary();
}
#endregion
#region Переводим слово.
private void translateButton_Click(object sender, EventArgs e)
{
translateTextBox.Text = null;
Translate tanslate = new Translate(wordTextBox.Text, translateTextBox, langComboBox.SelectedIndex);
}
#endregion |
|
class NewWord
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Словарь
{
public partial class NewWord
{
public TextBox wordTextBox;
public TextBox translateTextBox;
public DialogResult AddWord()
{
#region Создаем форму.
Form wordForm = new Form();
wordForm.StartPosition = FormStartPosition.CenterScreen;
wordForm.FormBorderStyle = FormBorderStyle.Fixed3D;
wordForm.Size = new Size(250, 180);
wordForm.MinimizeBox = false;
wordForm.MaximizeBox = false;
wordForm.Text = "Новое слово";
#endregion
#region Создаем метки.
Label wordLabel = new Label();
wordLabel.Location = new Point(10, 10);
wordLabel.AutoSize = false;
wordLabel.Size = new Size(230, 25);
wordLabel.Font = new Font("Times New Roman", 12, FontStyle.Bold);
wordLabel.Text = "Слово: ";
Label translateLabel = new Label();
translateLabel.Location = new Point(10, 60);
translateLabel.AutoSize = false;
translateLabel.Size = new Size(230, 25);
translateLabel.Font = new Font("Times New Roman", 12, FontStyle.Bold);
translateLabel.Text = "Перевод: ";
#endregion
#region Создаем текстовые поля.
wordTextBox = new TextBox();
wordTextBox.Location = new Point(10, 35);
wordTextBox.Size = new Size(215, 25);
wordTextBox.Text = null;
translateTextBox = new TextBox();
translateTextBox.Location = new Point(10, 85);
translateTextBox.Size = new Size(215, 25);
translateTextBox.Text = null;
#endregion
#region Создаем кнопки.
Button okButton = new Button();
okButton.Location = new Point(80, 115);
okButton.Size = new Size(70, 25);
okButton.DialogResult = DialogResult.OK;
okButton.Text = "OK";
Button cancelButton = new Button();
cancelButton.Location = new Point(155, 115);
cancelButton.Size = new Size(70, 25);
cancelButton.DialogResult = DialogResult.Cancel;
cancelButton.Text = "Cancel";
#endregion
#region Добавляем на форму компоненты и отображаем саму форму.
wordForm.Controls.Add(wordLabel);
wordForm.Controls.Add(translateLabel);
wordForm.Controls.Add(wordTextBox);
wordForm.Controls.Add(translateTextBox);
wordForm.Controls.Add(okButton);
wordForm.Controls.Add(cancelButton);
wordLabel.Show();
translateLabel.Show();
wordTextBox.Show();
translateTextBox.Show();
okButton.Show();
cancelButton.Show();
wordForm.ShowDialog();
#endregion
return wordForm.DialogResult;
}
}
} |
|
class ViewDictionary
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace Словарь
{
public partial class ViewDictionary
{
string[] ruText = new string[File.ReadAllLines("ru.txt").Length];
string[] ukrText = new string[File.ReadAllLines("ukr.txt").Length];
public ViewDictionary()
{
#region Создаем форму.
Form viewDictionaryForm = new Form();
viewDictionaryForm.StartPosition = FormStartPosition.CenterScreen;
viewDictionaryForm.FormBorderStyle = FormBorderStyle.Fixed3D;
viewDictionaryForm.Size = new Size(250, 185);
viewDictionaryForm.MinimizeBox = false;
viewDictionaryForm.MaximizeBox = false;
viewDictionaryForm.Text = "Просмотр словаря";
#endregion
#region Создаем RichTextBox.
RichTextBox richText = new RichTextBox();
richText.Location = new Point(10, 10);
richText.Size = new Size(215, 105);
richText.ScrollBars = RichTextBoxScrollBars.ForcedVertical;
richText.ReadOnly = true;
for (int i = 0; i < ruText.Length; i++)
{
ruText[i] = File.ReadAllLines("ru.txt")[i];
ukrText[i] = File.ReadAllLines("ukr.txt")[i];
richText.AppendText(ruText[i] + " - " + ukrText[i] + "\n");
}
viewDictionaryForm.Controls.Add(richText);
#endregion
#region Создаем кнопку.
Button closeButton = new Button();
closeButton.Location = new Point(150, 120);
closeButton.Size = new Size(75, 25);
closeButton.Text = "Закрыть";
closeButton.DialogResult = DialogResult.OK;
viewDictionaryForm.Controls.Add(closeButton);
#endregion
viewDictionaryForm.ShowDialog();
}
}
} |
|
class Translate
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Словарь
{
public partial class Translate
{
string[] ru = new string[File.ReadAllLines("ru.txt").Length];
string[] ua = new string[File.ReadAllLines("ukr.txt").Length];
public Translate(string word, TextBox textBox, int index)
{
#region Переводим с русского.
if (index == 0)
{
for (int i = 0; i < ru.Length; i++)
{
ru[i] = File.ReadAllLines("ru.txt")[i];
ua[i] = File.ReadAllLines("ukr.txt")[i];
if (ru[i].Equals(word, StringComparison.CurrentCultureIgnoreCase))
{
textBox.Text = ua[i];
return;
}
}
}
#endregion
#region Переводим с украинского.
if (index == 1)
{
for (int i = 0; i < ua.Length; i++)
{
ua[i] = File.ReadAllLines("ukr.txt")[i];
ru[i] = File.ReadAllLines("ru.txt")[i];
if (ua[i].Equals(word, StringComparison.CurrentCultureIgnoreCase))
{
textBox.Text = ru[i];
return;
}
}
}
#endregion
}
}
} |
|
1
|