C# 中使用 OwnerDraw ListView 进行字符对齐

发布于 2024-07-13 23:07:29 字数 256 浏览 17 评论 0原文

我正在尝试实现一个功能类似于 Firefox Awesome Bar 的 .NET 控件。 为此,我尝试在 ListView 中显示的搜索结果中对搜索到的字符进行粗体和下划线。 我已经设置了 OwnerDraw 并使用 Graphics.MeasureCharacterRanges 来计算字符有多大。 我遇到的问题是从该方法传回的值并不总是完美的。 我最终得到了一些额外的像素,或者两个彼此太接近的字符。 有一个简单的解决办法吗? 另一种使用不同字体设置绘制同一单词的不同部分的方法?

I'm trying to implement a .NET control that functions like the Firefox Awesome Bar. To that end, I'm trying to bold and underline searched for characters inside of search results displayed in a ListView. I've set up OwnerDraw and I'm using Graphics.MeasureCharacterRanges to figure out how big the characters are. The problem I'm having is that the values passed back from that method aren't always perfect. I end up with a few extra pixels here and there or two characters that are too close to each other. Is there an easy fix? Another way to draw different parts of the same word with different font settings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野稚 2024-07-20 23:07:29

我明白了这一点。 我不得不改用 TextRenderer.DrawText 和 TextRenderer.MeasureText。 我确保将 TextFormatFlags.NoPadding 传递给这两个方法。

I figured this out. I had to switch to using TextRenderer.DrawText and TextRenderer.MeasureText. I made sure to pass TextFormatFlags.NoPadding to both of those methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文