mirror of
https://github.com/project-redbud/FunGame-Desktop.git
synced 2025-04-23 21:49:34 +08:00
108 lines
2.9 KiB
C#
108 lines
2.9 KiB
C#
using System.ComponentModel;
|
||
using System.Runtime.InteropServices;
|
||
|
||
namespace Milimoe.FunGame.Desktop.Library.Component
|
||
{
|
||
[ToolboxBitmap(typeof(TextBox))]
|
||
partial class TextArea : RichTextBox
|
||
{
|
||
private string _emptyTextTip = "";
|
||
private Color _emptyTextTipColor = Color.DarkGray;
|
||
private const int WM_PAINT = 0xF;
|
||
|
||
public TextArea() : base()
|
||
{
|
||
|
||
}
|
||
|
||
[DefaultValue("")]
|
||
public string EmptyTextTip
|
||
{
|
||
get { return _emptyTextTip; }
|
||
set
|
||
{
|
||
_emptyTextTip = value;
|
||
base.Invalidate();
|
||
}
|
||
}
|
||
|
||
[DefaultValue(typeof(Color), "DarkGray")]
|
||
public Color EmptyTextTipColor
|
||
{
|
||
get { return _emptyTextTipColor; }
|
||
set
|
||
{
|
||
_emptyTextTipColor = value;
|
||
base.Invalidate();
|
||
}
|
||
}
|
||
|
||
protected override void WndProc(ref Message m)
|
||
{
|
||
base.WndProc(ref m);
|
||
if (m.Msg == WM_PAINT)
|
||
{
|
||
WmPaint(ref m);
|
||
}
|
||
}
|
||
|
||
private void WmPaint(ref Message m)
|
||
{
|
||
using (Graphics graphics = Graphics.FromHwnd(base.Handle))
|
||
{
|
||
if (Text.Length == 0
|
||
&& !string.IsNullOrEmpty(_emptyTextTip)
|
||
&& !Focused)
|
||
{
|
||
TextFormatFlags format =
|
||
TextFormatFlags.EndEllipsis |
|
||
TextFormatFlags.VerticalCenter;
|
||
|
||
if (RightToLeft == RightToLeft.Yes)
|
||
{
|
||
format |= TextFormatFlags.RightToLeft | TextFormatFlags.Right;
|
||
}
|
||
|
||
TextRenderer.DrawText(
|
||
graphics,
|
||
_emptyTextTip,
|
||
Font,
|
||
base.ClientRectangle,
|
||
_emptyTextTipColor,
|
||
format);
|
||
}
|
||
}
|
||
}
|
||
|
||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||
private static extern IntPtr LoadLibrary(string lpFileName);
|
||
protected override CreateParams CreateParams
|
||
{
|
||
get
|
||
{
|
||
CreateParams prams = base.CreateParams;
|
||
if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
|
||
{
|
||
prams.ExStyle |= 0x020; // transparent
|
||
prams.ClassName = "RICHEDIT50W";
|
||
}
|
||
return prams;
|
||
}
|
||
}
|
||
|
||
public void AppendImage(string filename)
|
||
{
|
||
//<2F><><EFBFBD><EFBFBD>Bitmap<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Bitmap bmp = new(filename);
|
||
//<2F><>Bitmap<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Clipboard.SetImage(bmp);
|
||
this.Paste();
|
||
}
|
||
|
||
public void AppendImage(Bitmap image)
|
||
{
|
||
Clipboard.SetImage(image);
|
||
this.Paste();
|
||
}
|
||
}
|
||
} |