-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelperFrm.cs
More file actions
204 lines (177 loc) · 5.7 KB
/
HelperFrm.cs
File metadata and controls
204 lines (177 loc) · 5.7 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ShapeMaker
{
public partial class HelpForm : Form
{
private List<bmark> hotspots = new List<bmark>();
private Dictionary<string, int> targets = new Dictionary<string, int>();
public HelpForm()
{
InitializeComponent();
}
private void HelpForm_Load(object sender, EventArgs e)
{
string strRtf = string.Empty;
Cursor.Current=Cursors.WaitCursor;
try
{
if (File.Exists(Application.StartupPath + @"\Effects\" + "ShapeMaker.rtf"))
{
using (TextReader tr = File.OpenText(Application.StartupPath + @"\Effects\" + "ShapeMaker.rtf"))
{
strRtf = tr.ReadToEnd();
}
}
else
{
MessageBox.Show("Help File Not Found!");
Cursor.Current = Cursors.Default;
return;
}
}
catch (Exception c)
{
MessageBox.Show("File Load Error - " + c);
Cursor.Current = Cursors.Default;
return;
}
if (strRtf == string.Empty)
{
Cursor.Current = Cursors.Default;
return;
}
int result = 0;
int result2 = 0;
int indexer = 0;
int stopper = 0;
RichTextBox rtbTmp = new RichTextBox();
//find bookmarks
string seek = @"{\*\bkmkstart ";
do
{
result = strRtf.IndexOf(seek, result);
if (result != -1)
{
result2 = strRtf.IndexOf("}", result);
int pos = result + seek.Length;
rtbTmp.Rtf = strRtf.Substring(0, result) + "}";
targets.Add(strRtf.Substring(pos, result2 - pos), rtbTmp.Text.Length);
result = result2;
}
} while (result != -1);
//find nyperlinks
result = 0;
seek = "HYPERLINK ";
do
{
result = strRtf.IndexOf(@seek, result);
if (result != -1)
{
string look = "{\\field";
result2 = strRtf.LastIndexOf(@look, result);
look = "" + (char)34;
int res = strRtf.IndexOf(look, result) + 1;
indexer = strRtf.IndexOf(look, res);
int counter = 0;
int len = result2;
do
{
string countchar = strRtf.Substring(len++, 1);
counter = (countchar == "{") ? counter + 1 : (countchar == "}") ? counter - 1 : counter;
} while (counter != 0);
stopper = len;
rtbTmp.Rtf = strRtf.Substring(0, result2) + "}";
int start2 = rtbTmp.Text.Length;
rtbTmp.Rtf = strRtf.Substring(0, stopper) + "}";
int end2 = rtbTmp.Text.Length;
hotspots.Add(new bmark()
{
BookMark = strRtf.Substring(res, indexer - res)
,
start = start2,
end = end2
});
result = stopper + 1;
}
} while (result != -1);
RTB.Rtf = strRtf;
strRtf = String.Empty;
rtbTmp.Dispose();
Cursor.Current = Cursors.Default;
}
private void RTB_MouseClick(object sender, MouseEventArgs e)
{
int index = RTB.GetCharIndexFromPosition(e.Location);
foreach (bmark h in hotspots)
{
if (h.start <= index && index <= h.end)
{
RTB.SelectionLength = 0;
RTB.SelectionStart = targets[h.BookMark];
RTB.ScrollToCaret();
}
}
}
private void RTB_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
private void RTB_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
private void RTB_LinkClicked(object sender, LinkClickedEventArgs e)
{
try
{
System.Diagnostics.Process.Start("http://www.getpaint.net/redirect/plugins.html");
}
catch (Exception ex)
{
MessageBox.Show("Unable to open the Link." + ex.Message);
}
}
private void RTB_MouseMove(object sender, MouseEventArgs e)
{
int index = RTB.GetCharIndexFromPosition(RTB.PointToClient(MousePosition));
bool hand = false;
foreach (bmark h in hotspots)
{
if (h.start <= index && index <= h.end) hand = true;
}
if (hand)
{
this.Cursor = Cursors.Hand;
}
else
{
this.Cursor = RTB.Cursor;
}
}
}
public class bmark
{
public string BookMark
{
get;
set;
}
public int start
{
get;
set;
}
public int end
{
get;
set;
}
}
}