forked from PavelTorgashov/FastColoredTextBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHyperlinkSample.cs
More file actions
53 lines (46 loc) · 1.57 KB
/
Copy pathHyperlinkSample.cs
File metadata and controls
53 lines (46 loc) · 1.57 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
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using FastColoredTextBoxNS;
namespace Tester
{
public partial class HyperlinkSample : Form
{
TextStyle blueStyle = new TextStyle(Brushes.Blue, null, FontStyle.Underline);
public HyperlinkSample()
{
InitializeComponent();
}
private void fctb_TextChangedDelayed(object sender, FastColoredTextBoxNS.TextChangedEventArgs e)
{
e.ChangedRange.ClearStyle(blueStyle);
e.ChangedRange.SetStyle(blueStyle, @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?");
}
bool CharIsHyperlink(Place place)
{
var mask = fctb.GetStyleIndexMask(new Style[] { blueStyle });
if (place.iChar < fctb.GetLineLength(place.iLine))
if ((fctb[place].style & mask) != 0)
return true;
return false;
}
private void fctb_MouseMove(object sender, MouseEventArgs e)
{
var p = fctb.PointToPlace(e.Location);
if (CharIsHyperlink(p))
fctb.Cursor = Cursors.Hand;
else
fctb.Cursor = Cursors.IBeam;
}
private void fctb_MouseDown(object sender, MouseEventArgs e)
{
var p = fctb.PointToPlace(e.Location);
if (CharIsHyperlink(p))
{
var url = fctb.GetRange(p, p).GetFragment(@"[\S]").Text;
Process.Start(url);
}
}
}
}