抽象与Drawtext性能 [英] Drawstring vs. Drawtext performance

查看:76
本文介绍了抽象与Drawtext性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义控件,里面使用了很多Label控件,在绘制/重绘屏幕时我开始遇到性能问题所以我决定删除它们,因为它们看起来压倒一切,只是绘制我需要的文本



我开始使用Graphics.DrawString方法,这是超快的,调整大小/重绘屏幕时的性能是完美的,但后来我注意到文本渲染不完全相同一个标签使用,看起来不那么好。



然后我发现了 TextRenderer.DrawText 方法,我切换到它,但问题又回来了,当你调整窗体/控件的大小时,性能很差。



这是正常行为吗?我研究了一下,然后开始读到 TextRenderer.DrawText 是更好和更好的,因为它使用GDI +而不是GDI,但这显然不是我的情况?



我们正在谈论一个100%标准的WinForm vb.net应用程序,启用了 VisualStyles



我尝试了什么:



 TextRenderer.DrawText(e。图形,  Hello World .Font,矩形( 1  1  200  20 ), .ForeColor,TextFormatFlags.Left)

e.Graphics.DrawString( Hello World .Font,_Brush, Rect角度( 1 1 200 20 ),_ StringFormat)

解决方案

在< a href =https://stackoverflow.com/questions/71374/fastest-api-for-rendering-text-in-windows-forms> c# - 用于在Windows窗体中呈现文本的最快API? - Stack Overflow [ ^ ]

I have a custom control that used a lot of Label controls inside, and i started experiencing performance issues when drawing/redrawing the screen So i decided to remove them as they look overwhelming and just draw the texts I needed

I started using Graphics.DrawString method, which was SUPER fast and the performance when resizing/redrawing the screen was perfect, but then I noticed the text render wasn't exactly the same as the one Labels uses, and didn't look that good.

I then found out about TextRenderer.DrawText method and I switched to it, but the problem came back again, when you resize the form/control the performance is awful.

Is this a normal behavior? I researched a bit and came to read that TextRenderer.DrawText is preferable and better as it uses GDI+ as opposed as GDI, but this clear is not my case?

We are talking about a 100% standard WinForm vb.net app with VisualStyles enabled.

What I have tried:

TextRenderer.DrawText(e.Graphics, "Hello World", Me.Font, New Rectangle(1, 1, 200, 20), Me.ForeColor, TextFormatFlags.Left)

e.Graphics.DrawString("Hello World", Me.Font, _Brush, New Rectangle(1, 1,200, 20), _StringFormat)

解决方案

There's a very nice conversation at c# - Fastest API for rendering text in Windows Forms? - Stack Overflow[^]


这篇关于抽象与Drawtext性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆