WinForms 工具提示中的文本长度
如何设置 WinForms 工具提示中文本的最大长度? 我有一个大约 300 个字符的字符串,但我的工具提示仅显示其中 264 个...
问候,
Jürgen
how to set the max length of a text in a WinForms ToolTip?
I have a String with about 300 chars, but my ToolTip displays only 264 of them...
Greets,
Jürgen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样在工具提示字符串中添加几次 NewLine ,这样它就不会一直穿过屏幕。
此代码中的字符串长度为 434 个字符。
:-)
请运行此代码来尝试一下:>>
You could add NewLine a few times in your ToolTip string like this so that it does not go all the way across the screen.
The string in this code is 434 characters long.
:-)
Just run this code to try it please:>>
我遇到了同样的问题(它恰好与 DataGridView 单元格有关),并且默认的工具提示文本(即单元格的文本内容)确实被截断。
对我来说,当我显式设置工具提示文本时,它开始正常工作(我看到的所有答案都是这样做的)。我认为微妙的是默认的工具提示文本使用相同的单元格内容,只有默认处理程序会截断它,如原始问题中所述。通过覆盖事件并设置工具提示文本(即使它是完全相同的单元格文本!),现在默认的长度限制似乎消失了。
当然,其他控件会触发不同的事件,但是如果您自己将文本放在工具提示上,那么您可以避免任何默认工具提示发生的截断。
I had this same issue (it happened to be with a DataGridView cell) and the default ToolTip text (i.e. the text content of the cell) was indeed being truncated.
For me, it started working correctly when I set the ToolTip text explicitly (all of the answers I see do this). What I think is subtle is that the default ToolTip text uses the same cell content, only the default handler does truncate it as noted in the original question. By overriding the event and setting the ToolTip text (even though it's exactly the same cell text!) now the default length restriction seems to go away.
Other controls will fire different events of course, but it should hold that if you put the text onto the tool tip yourself then you can circumvent the truncation that occurs with any default ToolTip.
我知道这是一个老问题,我不确定当时是否存在以下功能,但是对于那些搜索此功能的人来说,我注意到如果工具提示文本很长,它可能根本不会显示,并且之后一些尝试,发现这有帮助:
I know this is an old question and I'm not sure if the following functionality existed at that time, but for those searching for this, I noticed that if the Tooltip text is very long, it may not get displayed at all, and after some trying, found that this helps: