This commit is contained in:
Alexander 2019-09-28 22:22:53 +03:00
parent 86656d85ca
commit c7992b0410
2 changed files with 56 additions and 1 deletions

View file

@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@ -34,5 +34,59 @@ protected override void WndProc(ref Message m)
base.WndProc(ref m);
}
public static class RichTextBoxPadding
{
public static void SetInnerMargins(this TextBoxBase textBox, int left, int top, int right, int bottom)
{
var rect = textBox.GetFormattingRect();
var newRect = new Rectangle(left, top, rect.Width - left - right, rect.Height - top - bottom);
textBox.SetFormattingRect(newRect);
}
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public readonly int Left;
public readonly int Top;
public readonly int Right;
public readonly int Bottom;
private RECT(int left, int top, int right, int bottom)
{
Left = left;
Top = top;
Right = right;
Bottom = bottom;
}
public RECT(Rectangle r) : this(r.Left, r.Top, r.Right, r.Bottom)
{
}
}
[DllImport(@"User32.dll", EntryPoint = @"SendMessage", CharSet = CharSet.Auto)]
private static extern int SendMessageRefRect(IntPtr hWnd, uint msg, int wParam, ref RECT rect);
[DllImport(@"user32.dll", EntryPoint = @"SendMessage", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, ref Rectangle lParam);
private const int EmGetrect = 0xB2;
private const int EmSetrect = 0xB3;
private static void SetFormattingRect(this TextBoxBase textbox, Rectangle rect)
{
var rc = new RECT(rect);
SendMessageRefRect(textbox.Handle, EmSetrect, 0, ref rc);
}
private static Rectangle GetFormattingRect(this TextBoxBase textbox)
{
var rect = new Rectangle();
SendMessage(textbox.Handle, EmGetrect, (IntPtr)0, ref rect);
return rect;
}
}
}
}
}

View file

@ -722,6 +722,7 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
}
}
richTextBox.SetInnerMargins(Convert.ToInt32(settings.editorPaddingLeft), 0, 0, 0);
private void MainWindow_Load(object sender, EventArgs e)
{