Paw*_*ęba 3 .net c# richtextbox selection winforms
是否有可能在用户选择后,每个选定的字母都会显示原始颜色?并不总是白色,因为它是默认的?
您可以使用最新版本,RichTextBox为此RICHEDIT50W,您应该继承标准RichTextBox并覆盖CreateParams并设置ClassName为RICHEDIT50W:
码
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class ExRichText : RichTextBox
{
[DllImport("kernel32.dll", EntryPoint = "LoadLibraryW",
CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr LoadLibraryW(string s_File);
public static IntPtr LoadLibrary(string s_File)
{
var module = LoadLibraryW(s_File);
if (module != IntPtr.Zero)
return module;
var error = Marshal.GetLastWin32Error();
throw new Win32Exception(error);
}
protected override CreateParams CreateParams
{
get
{
var cp = base.CreateParams;
try
{
LoadLibrary("MsftEdit.dll"); // Available since XP SP1
cp.ClassName = "RichEdit50W";
}
catch { /* Windows XP without any Service Pack.*/ }
return cp;
}
}
}
Run Code Online (Sandbox Code Playgroud)
截图
注意:
由于这个古老有用的视觉工作室工具,我可以使用Spy ++看到wordpad的RichTextBox类.
如果你有过任何问题,RICHEDIT50W在您的操作系统,你可以打开Spy++和WordPad,然后选择RichTextBox它,看看有什么类的名称.
RICHEDIT50W课程应用到我的控制中时,我到达了@Elmue 这个伟大的帖子,感谢他.