private void from1_DoubleClick(object sender, EventArgs e)
{
TextBox mytestbox = new TextBox()
mytestbox.Location = PointToClient(MousePosition)
mytestbox.Size = new Size(100,50)//自己调整
this.Controls.Add(mytestbox)//添加,添到哪里自己调整
}
在 CefSharp 中设置字体库为宋体的方法如下:1. 在项目中添加字体文件:将宋体字体文件添加到项目中,并将字体文件设置为嵌入式资源。
2. 在程序启动时加载字体库:在应用程序启动时,添加以下代码来加载自定义字体库:
```CSharp
// 注册自定义字体
private void RegisterCustomFont()
{
var customFontPath = "YourCustomFontFileLocation"
var fontCollection = new PrivateFontCollection()
fontCollection.AddFontFile(customFontPath)
// 定义 CefSettings 对象
var settings = new CefSettings()
// 设置 CefSharp 字体
settings.CefCommandLineArgs.Add("force-device-scale-factor", "1.0")
settings.CefCommandLineArgs.Add("disable-direct-write", "1")
settings.CefCommandLineArgs.Add("disable-gpu", "1")
var fontCollectionFamilyName = "CustomFontFamilyName"
if (fontCollection.Families.Length >0)
{
fontCollectionFamilyName = fontCollection.Families[0].Name
}
//注册自定义字体
settings.RegisterScheme(new CefCustomFontScheme
{
FontFamilyName = fontCollectionFamilyName,
FolderPath = AppDomain.CurrentDomain.BaseDirectory,
Name = "custom"
})
//初始化 CefSharp
Cef.Initialize(settings)
}
```
在上述代码中,将 YourCustomFontFileLocation 替换为你的自定义字体文件所在的路径,将 CustomFontFamilyName 替换为你的自定义字体家族名称。
3. 使用自定义字体库:按照以下步骤在 CefSharp 控制器中设置宋体为默认字体:
```CSharp
var settings = new BrowserSettings()
settings.StandardFontFamily = "custom"
settings.FixedFontFamily = "custom"
settings.SerifFontFamily = "custom"
settings.SansSerifFontFamily = "custom"
settings.CursiveFontFamily = "custom"
settings.FantasyFontFamily = "custom"
```
以上就是在 CefSharp 中设置字体库为宋体的步骤。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)