Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23768dbe0e |
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.21
|
1.0.22
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<RootNamespace>MonsterMonitor</RootNamespace>
|
<RootNamespace>MonsterMonitor</RootNamespace>
|
||||||
<AssemblyName>devenv</AssemblyName>
|
<AssemblyName>devenv</AssemblyName>
|
||||||
<AssemblyVersion>1.0.21</AssemblyVersion>
|
<AssemblyVersion>1.0.22</AssemblyVersion>
|
||||||
<Version>1.0.21</Version>
|
<Version>1.0.22</Version>
|
||||||
<FileVersion>1.0.21</FileVersion>
|
<FileVersion>1.0.22</FileVersion>
|
||||||
<InformationalVersion>1.0.21</InformationalVersion>
|
<InformationalVersion>1.0.22</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MonsterMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
@@ -9,6 +10,9 @@ namespace MonsterMonitor.UI
|
|||||||
{
|
{
|
||||||
public sealed class MainForm : Form
|
public sealed class MainForm : Form
|
||||||
{
|
{
|
||||||
|
private const int EmGetFirstVisibleLine = 0x00CE;
|
||||||
|
private const int EmLineScroll = 0x00B6;
|
||||||
|
|
||||||
private readonly RichTextBox _console = new RichTextBox();
|
private readonly RichTextBox _console = new RichTextBox();
|
||||||
private readonly Button _btnSettings = new Button();
|
private readonly Button _btnSettings = new Button();
|
||||||
private readonly Button _btnExit = new Button();
|
private readonly Button _btnExit = new Button();
|
||||||
@@ -192,14 +196,49 @@ namespace MonsterMonitor.UI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wasNearBottom = IsConsoleNearBottom();
|
||||||
|
var firstVisibleLineBeforeAppend = GetFirstVisibleLine(_console);
|
||||||
|
|
||||||
_console.SelectionStart = _console.TextLength;
|
_console.SelectionStart = _console.TextLength;
|
||||||
_console.SelectionLength = 0;
|
_console.SelectionLength = 0;
|
||||||
_console.SelectionColor = GetColor(entry.Level);
|
_console.SelectionColor = GetColor(entry.Level);
|
||||||
_console.AppendText($"[{entry.Timestamp:HH:mm:ss}] [{entry.Level}] {entry.Message}{Environment.NewLine}");
|
_console.AppendText($"[{entry.Timestamp:HH:mm:ss}] [{entry.Level}] {entry.Message}{Environment.NewLine}");
|
||||||
_console.SelectionColor = _console.ForeColor;
|
_console.SelectionColor = _console.ForeColor;
|
||||||
|
|
||||||
|
if (wasNearBottom)
|
||||||
|
{
|
||||||
_console.ScrollToCaret();
|
_console.ScrollToCaret();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var firstVisibleLineAfterAppend = GetFirstVisibleLine(_console);
|
||||||
|
var linesToRestore = firstVisibleLineBeforeAppend - firstVisibleLineAfterAppend;
|
||||||
|
if (linesToRestore != 0)
|
||||||
|
{
|
||||||
|
SendMessage(_console.Handle, EmLineScroll, IntPtr.Zero, (IntPtr)linesToRestore);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsConsoleNearBottom()
|
||||||
|
{
|
||||||
|
if (_console.TextLength == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bottomLeftPoint = new Point(1, Math.Max(0, _console.ClientSize.Height - 1));
|
||||||
|
var lastVisibleCharIndex = _console.GetCharIndexFromPosition(bottomLeftPoint);
|
||||||
|
return lastVisibleCharIndex >= _console.TextLength - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetFirstVisibleLine(RichTextBox richTextBox)
|
||||||
|
{
|
||||||
|
return SendMessage(richTextBox.Handle, EmGetFirstVisibleLine, IntPtr.Zero, IntPtr.Zero).ToInt32();
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||||
|
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||||
|
|
||||||
private void ConfigureUpdateTimer()
|
private void ConfigureUpdateTimer()
|
||||||
{
|
{
|
||||||
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;
|
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;
|
||||||
|
|||||||
Reference in New Issue
Block a user