forked from PavelTorgashov/FastColoredTextBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoggerSample.cs
More file actions
64 lines (59 loc) · 1.96 KB
/
Copy pathLoggerSample.cs
File metadata and controls
64 lines (59 loc) · 1.96 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastColoredTextBoxNS;
namespace Tester
{
public partial class LoggerSample : Form
{
TextStyle infoStyle = new TextStyle(Brushes.Black, null, FontStyle.Regular);
TextStyle warningStyle = new TextStyle(Brushes.BurlyWood, null, FontStyle.Regular);
TextStyle errorStyle = new TextStyle(Brushes.Red, null, FontStyle.Regular);
public LoggerSample()
{
InitializeComponent();
}
private void tm_Tick(object sender, EventArgs e)
{
switch (DateTime.Now.Millisecond % 3)
{
case 0:
Log(DateTime.Now + " Error\r\n", errorStyle); break;
case 1:
Log(DateTime.Now + " Warning\r\n", warningStyle); break;
case 2:
Log(DateTime.Now + " Info\r\n", infoStyle); break;
}
}
private void Log(string text, Style style)
{
//some stuffs for best performance
fctb.BeginUpdate();
fctb.Selection.BeginUpdate();
//remember user selection
var userSelection = fctb.Selection.Clone();
//add text with predefined style
fctb.AppendText(text, style);
//restore user selection
if (!userSelection.IsEmpty || userSelection.Start.iLine < fctb.LinesCount - 2)
{
fctb.Selection.Start = userSelection.Start;
fctb.Selection.End = userSelection.End;
}
else
fctb.GoEnd();//scroll to end of the text
//
fctb.Selection.EndUpdate();
fctb.EndUpdate();
}
private void btGotToEnd_Click(object sender, EventArgs e)
{
fctb.GoEnd();
}
}
}