2019-1-24-WPF-文字描边
2024-10-07 14:42:01
title | author | date | CreateTime | categories |
---|---|---|---|---|
WPF 文字描边
|
lindexi
|
2019-01-24 19:47:18 +0800
|
2019-1-24 19:40:7 +0800
|
WPF
|
本文告诉大家如何写出描边的字体
在WPF如果需要写入描边需要使用 FormattedText 将文字转换为 Geometry 然后通过画出 Geometry 的边框和填充画出描边
首先创建一个类继承 UIElement 这样就可以重写 OnRender 方法在里面画出文字
假设需要画出的文字是 欢迎访问我博客 http://lindexi.gitee.io 里面有大量 UWP WPF 博客
protected override void OnRender(DrawingContext drawingContext)
{
var str = "欢迎访问我博客 http://lindexi.gitee.io 里面有大量 UWP WPF 博客"; base.OnRender(drawingContext);
}
通过字符串创建 FormattedText 这里需要传入很多参数
var formattedText = new FormattedText(str, CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface
(
new FontFamily("微软雅黑"),
FontStyles.Normal,
FontWeights.Normal,
FontStretches.Normal
),
30,
Brushes.Black, 96);
调用 formattedText.BuildGeometry 可以创建 Geometry 参数传入左上角坐标
然后就是画出这个 Geometry 通过这个 Pen 设置描边的宽度和颜色
drawingContext.DrawGeometry
(
new SolidColorBrush((Color) ColorConverter.ConvertFromString("#F00002")),
new Pen(new SolidColorBrush(Colors.Black), 1),
geometry
);
打开 xaml 添加这个控件运行代码就可以看到上面界面
<local:CureekaMasar></local:CureekaMasar>
所有代码请看下面
protected override void OnRender(DrawingContext drawingContext)
{
var str = "欢迎访问我博客 http://lindexi.gitee.io 里面有大量 UWP WPF 博客"; var formattedText = new FormattedText(str, CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface
(
new FontFamily("微软雅黑"),
FontStyles.Normal,
FontWeights.Normal,
FontStretches.Normal
),
30,
Brushes.Black, 1); var geometry = formattedText.BuildGeometry(new Point(10, 10)); drawingContext.DrawGeometry
(
new SolidColorBrush((Color) ColorConverter.ConvertFromString("#F00002")),
new Pen(new SolidColorBrush(Colors.Black), 1),
geometry
); base.OnRender(drawingContext);
}
最新文章
- UEFI模式安装Win10和Linux双系统
- VS2012 单元测试之泛型类(Generics Unit Test)
- nodejs处理图片、CSS、JS链接
- Windows phone应用开发[18]-下拉刷新
- 以下css可以清除浮动
- Android Studio 引入Lambda表达式
- android sdk国内快速更新下载
- visual studio 2012 使用 git/github
- Ubuntu14.04下搜狗输入法的安装及配置
- SpringMVC中redirect跳转后如何保存Model中的数据?
- (转) Linux中profile、bashrc、bash_profile之间的区别和联系
- STM32 USB 鼠标+键盘 串口控制
- jmeter打开图形化界面时指定代理
- appium启动
- linux学习笔记-lrmi源码包的编译安装方法
- Benchmark Web App 性能瓶颈分析与性能测试工具的使用方法总结
- 【转】C#如何创建泛型类T的实例
- linux下如何启动sybase
- hdu 1042 N! java大数及判断文件末尾
- 使用Vmware虚拟机部署Swift开发环境之Mac OSX系统安装
热门文章
- 使用Node,Vue和ElasticSearch构建实时搜索引擎
- git log的个性化设置
- 19.go语言基础学习(下)——2019年12月16日
- python开发之virtualenv与virtualenvwrapper
- Python---基础---str
- 利用xcode Build生成模拟器运行包
- django搭建一个小型的服务器运维网站-用户登陆与session
- rssi pdf 单双峰正态发布 与 定位
- 匿名函数 sorted() filter() map() 递归函数
- 实验1 C语言开发环境...