当前位置:网站首页>C# TextBlock 上标
C# TextBlock 上标
2022-08-04 14:49:00 【林德熙】
我需要做一个函数,显示 x^2 ,但是看起来用 TextBlock 做的不好看。 我用 WPF 写的上标看起来不好看,但是最后有了一个简单方法让他好看。 本文告诉大家如何做一个好看的上标。
一开始做的方法:
把下面代码写在页面里,使用对齐是上面,改变字号,于是看起来就是上标。
<TextBlock x:Name="TextBlock">
<Run Text="y=x"></Run>
<Run Text="2" BaselineAlignment="TextTop"
FontSize="8"></Run>
</TextBlock>
于是看起来:
其实已经可以了,但是发现距离很大,那么如何让距离变小?
我找了很久,发现可以在 xaml.cs 上写。
var textBlock = TextBlock;
textBlock.Inlines.Add(new Run("y = "));
textBlock.Inlines.Add(new Run("x"));
Run run=new Run();
run.FontSize = 7;
run.BaselineAlignment = BaselineAlignment.TextTop;
run.Text = "2";
textBlock.Inlines.Add(run);
代码一样,但是写的地方不一样,可以看到现在的上标就好看了。
UWP 上标也一样。为什么写在 Xaml 间隔会那么大,是不是WR弄的?其实试试下面代码,注意不要格式化,直接写的样子和我的一样试试。
<TextBlock x:Name="TextBlock">
<TextBlock.Inlines>
<Run Text="y=x"/><Run Text="2" BaselineAlignment="TextTop"
FontSize="8"/>
</TextBlock.Inlines>
</TextBlock>
原因就是Run写在两行,会把换行给记下,于是间隔就大了,写在一起的Run就不会出现这个距离。
但是我的 格式化会把Run放在下一行,所以可能我这里看的好的,在你这就会换行,看起来上标就有了距离。
我把他传上 csdn ,大家可以下载来验证。
边栏推荐
- RS|哨兵二号(.SAFE格式)转tif格式
- 实际工作中的高级技术(训练加速、推理加速、深度学习自适应、对抗神经网络)
- 一看就会的Chromedriver(谷歌浏览器驱动)安装教程
- Technology sharing | Mini program realizes audio and video calls
- leetcode: 251. Expanding 2D Vectors
- B.构造一个简单的数列(贪心)
- 基于 Next.js实现在线Excel
- 微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
- JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture
- 16、学习MySQL 正则表达式
猜你喜欢
基本介绍PLSQL
微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
Almost all known protein structures in the world are open sourced by DeepMind
数据库恢复
Technology sharing | Description of the electronic fence function in the integrated dispatching system
Leetcode: 215 disorderly to find the first big k element in the array
Qt的QItemDelegate使用
并发程序的隐藏杀手——假共享(False Sharing)
关于pnpm包管理器的版本问题
广告电商系统开发功能只订单处理
随机推荐
1403. Minimum Subsequence in Non-Increasing Order
F.金玉其外矩阵(构造)
杭电校赛(ACM组队安排)
This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
Phasecraft连下两城,助力英国量子技术商业化加速!
一看就会的Chromedriver(谷歌浏览器驱动)安装教程
[Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
[Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
兆骑科创创新创业大赛活动举办,线上直播路演,投融资对接
我爱七夕哈哈哈
vim 常用操作命令
杭电校赛(逆袭指数)
License server system does not support this version of this feature
7 天能找到 Go 工作吗?学学 Go 数组和指针试试
X射线掠入射聚焦反射镜
Hangzhou Electric School Competition (Counter Attack Index)
Crawler - action chain, xpath, coding platform use
数据链路层-------以太网协议
uni-app 从零开始-生命周期(二)