C# 中使用 OwnerDraw ListView 进行字符对齐
我正在尝试实现一个功能类似于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我明白了这一点。 我不得不改用 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.