-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormFind.cs
71 lines (60 loc) · 2.31 KB
/
FormFind.cs
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
using System;
using System.Drawing;
using System.Windows.Forms;
namespace KPFU_2_sem_programming_NotepadPlusPlus {
public partial class FormFind : Form {
public RichTextBox mainTextField;
public int startIndex = 0;
public FormFind(ref RichTextBox richTextBox) {
InitializeComponent();
this.Icon = new Icon(FormMain.pathIconBlue);
mainTextField = richTextBox;
startIndex = mainTextField.SelectionStart;
}
private void findButtonFindMore_Click(object sender, EventArgs e) {
if (findTextField.Text.Length == 0) {
findLabel2.Text = "Введите текст";
return;
}
string source;
string dest;
if (findCheckRegister.Checked) {
source = mainTextField.Text;
dest = findTextField.Text;
} else {
source = mainTextField.Text.ToLower();
dest = findTextField.Text.ToLower();
}
find(source, dest, findGroupBoxRadioButtonDown.Checked);
}
private void findButtonCancel_Click(object sender, EventArgs e) {
this.DialogResult = DialogResult.Cancel;
this.Close();
}
void find(string source, string dest, bool toDown) {
if (source.Contains(dest)) {
int endIndex = source.Length - dest.Length;
if (toDown) {
for (int i = startIndex; i < endIndex; i++) {
if (source.Substring(i, dest.Length) == dest) {
mainTextField.Select(i, dest.Length);
startIndex = i + 1;
break;
}
}
} else {
for (int i = startIndex; i > 0; i--) {
if (source.Substring(i, dest.Length) == dest) {
mainTextField.Select(i, dest.Length);
startIndex = i - 1;
break;
}
}
}
} else {
FormFindNone formFindNone = new FormFindNone(findTextField.Text);
formFindNone.Show();
}
}
}
}