android 富文本带边框,文本和边框之间的富文本框填充

public static class RichTextBoxExtensions

{

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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值