Windows窗体中的C#垂直标签
发布时间:2020-12-13 20:48:24 所属栏目:Windows 来源:网络整理
导读:是否可以在 Windows Forms中垂直显示标签? 标签很简单,您只需覆盖Paint事件并垂直绘制文本即可。请注意,GDI已针对水平绘制文本进行了优化。如果你旋转文字(即使你旋转90度的倍数),它看起来会更糟。 也许最好的办法是将文本绘制(或获取自己绘制的标签)到
是否可以在
Windows Forms中垂直显示标签?
标签很简单,您只需覆盖Paint事件并垂直绘制文本即可。请注意,GDI已针对水平绘制文本进行了优化。如果你旋转文字(即使你旋转90度的倍数),它看起来会更糟。
也许最好的办法是将文本绘制(或获取自己绘制的标签)到位图上,然后显示旋转的位图。 一些用于使用垂直文本绘制自定义控件的C#代码。请注意,如果文本不是水平的,则ClearType文本永远不会起作用: using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; public partial class VerticalLabel : UserControl { public VerticalLabel() { InitializeComponent(); } private void VerticalLabel_SizeChanged(object sender,EventArgs e) { GenerateTexture(); } private void GenerateTexture() { StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; format.Trimming = StringTrimming.EllipsisCharacter; Bitmap img = new Bitmap(this.Height,this.Width); Graphics G = Graphics.FromImage(img); G.Clear(this.BackColor); SolidBrush brush_text = new SolidBrush(this.ForeColor); G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; G.DrawString(this.Name,this.Font,brush_text,new Rectangle(0,img.Width,img.Height),format); brush_text.Dispose(); img.RotateFlip(RotateFlipType.Rotate270FlipNone); this.BackgroundImage = img; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 安装 – WiX:安装服务为LocalService
- 修复win10设置还原点时出现的80042302错误
- 在Windows中使用Python查找SC_PAGE_SIZE
- 解决windows64位系统上安装mysql-python报错
- windows-phone – Windows Phone 8 IconicTemplate Tile Im
- windows-server-2008 – 用于Windows 2008 RDP的fail2ban
- windows-server-2008 – 修改Active Directory连接对象
- 经验丰富的Windows SysAdmin应该如何学习Linux?
- 将Windows Mono运行时与应用程序捆绑在一起
- Windows Azure是否为虚拟机提供静态IP?
推荐文章
站长推荐
- windows – 没有窗口图标的Qt对话框(系统菜单)
- 如何在Windows中为当前用户的登录会话获取唯一ID
- Pacman常用命令
- Win10 64位 安装 .NetFramework 3.5
- Windows 10 Creators更新打破了WinForms应用程序
- .net – Windows 8是否支持System.Device.Locati
- windows-server-2008 – 具有错误子网掩码的VPN
- Windows Server 2012 R2 DataCenter列出指定服务
- 在常规桌面计算机上运行Windows Server OS
- windows-services – 使用一个Windows服务执行作
热点阅读