使用 DrawText 绘制文本的结尾
当目标矩形太小时,TextRenderer.DrawText()
是否能够绘制文本的末尾?
TextFormatFlags.Bottom
没有帮助我。
换句话说:如何在其顶部边缘剪切文本?
Is TextRenderer.DrawText()
capable to draw the end of a text when destination rectangle is too small?
TextFormatFlags.Bottom
didn't helped me.
In others words: how to clip text on its top edge?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个内存位图,其大小为“溢出区域”。使用 -Y 坐标将文本字符串绘制到此溢出区域,以便它绘制出与要剪辑的区域对齐的图像顶部。现在,您可以在图像中绘制溢出文本,将其绘制在您想要的位置。
例如,如果您想要在只能显示 75 像素的区域中绘制 100 像素高的文本,请创建一个 25 像素高的图像,并将文本绘制到该图像的 y=-75 处。
Create an in memory bitmap that is the size of the "overflow area". Draw your text string to this overflow area with a -Y coord that so that it draws off the top of the image that lines up with the area you want to clip to. You now have the overflow text in an image that you can paint where you want it.
For example, if you want to draw text that is 100 pixel high in an area that can only show 75 pixels, create a 25 pixel high image, and draw your text to that image at y=-75.