用于在固定区域中显示文本的控件 [英] Which control to use to display text in a fixed area

查看:82
本文介绍了用于在固定区域中显示文本的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在winform应用程序中工作,我必须在固定区域(固定大小的区域)中显示文本,尽管有更多文本,即它应该在容纳区域中显示可能的文本并留下其他文本不是容纳。文本也是文本(字母大小可以是小的大胆色等)。



我尝试使用WebBrowser控件。但是,由于区域被固定为显示富文本,因此当字母大小太大时,有时字母会显示一半。就WebBrowser控件而言,我是否遗漏了一些东西?或者还有其他任何可以提供帮助的控件吗?



我也在寻找像Label控件那样的AutoEllipsis属性。



有什么建议吗?

I am working in a winform application where I have to show the text in a fixed area (area of fixed size) although there are more text i.e it should show the possible texts in the accommodated area and leave other text which are not accommodated. Also the text is reach text(the letter size can be small big bold colored etc.).

I tried using the WebBrowser control. But as the area is fixed to display rich text, sometimes the letters are half displayed when the letter size is too large. Am I missing something as far as WebBrowser control is concerned? Or is there any other control which can help ?

Also I am looking for something like the AutoEllipsis property as exists for the Label control.

Any suggestion ?

推荐答案

当内容包含多个字体和/或多个字体时,准确测量RichTextBox中任意RTF内容的大小字体大小和/或多种字体样式是一个难题!



1.为什么不在RichTextBox上使用'Scrollbars:'将'ScrollBars属性设置为两者都会根据需要自动显示?有时最简单是最好的!



2.我见过的唯一适合RTF到容器的解决方案是Blake Robertson:[ ^ ];来源:[ ^ ]。他的GitHub网站已经停产,我不知道他的代码处于什么状态。



3.如果你愿意扩展RichTextBox的大小那么RTF in它完全可见,我在StackOverFlow上看到了几种解决方案。只需搜索RichTextBox适合文本。



3.a.另一个策略是设计一个同时具有RichTextBox和一种激活器(Label?Button?Pa​​nel?)的UserControl,当你点击它时它会:>


3.a.1。将RichTextBox的大小扩展到某个预定义的状态



或者,



3.a. 2。激活ScrollBars



除非您是高级开发人员并且非常熟悉在WinForms(P / Invoke)中使用API​​调用,否则我建议您只使用ScrollBars。 />


4.嗯...等一下......这是最后的想法:当用户点击小显示屏时,使用弹出窗体显示RTF窗口在窗体上。



您可以使用此处显示的技术在TextBox中显示纯文本(一种字体,一种样式,大小):[ ^ ]适合您的TextBox区域,然后,当用户单击它,或单击一些控件:然后显示带有RichTextBox的弹出窗体。
Accurately measuring the size of arbitrary RTF content in a RichTextBox when that content contains multiple Fonts and/or multiple Font Sizes, and/or multiple Font Styles is a hard problem !

1. why don't you just use 'Scrollbars on the RichTextBox: set 'ScrollBars property to 'Both so they'll automatically appear as needed ? Sometimes simplest is best !

2. the only fit-RTF-to-container solution I've seen is by Blake Robertson: [^]; source here: [^]. His GitHub site is discontinued and I have no idea what state his code is in.

3. if you are willing to expand the size of the RichTextBox so the RTF in it is fully visible, there are several solutions I've seen on StackOverFlow. Just search on "RichTextBox fit text."

3.a. another strategy would be to design a UserControl that had both a RichTextBox, and a kind of "activator" (Label ?Button ? Panel ?) that when you clicked it it would either:

3.a.1. expand the size of the RichTextBox to some pre-defined state

or,

3.a.2. activate the ScrollBars

Unless you are a senior developer and very familiar with using API calls in WinForms (P/Invoke), I advise you to just use ScrollBars.

4. well ... wait a minute ... here's a final thought: use a pop-up Form to display the RTF when the user clicks on the "small display window" on the Form.

You can use the technique shown here for showing plain text (one font, one style, on size) in a TextBox: [^] fitted to your TextBox area, then, when the user clicks on it, or clicks some Control: then show a pop-up Form with a RichTextBox.


您应该能够使用WebBrowser控件执行您的名称。将您的富文本格式化为HTML,包括字体大小,颜色等,你应该好好去...
You should be able to do what you name with the WebBrowser Control. Format your Rich Text as HTML including your font size, color etc and you should be good to go...


这篇关于用于在固定区域中显示文本的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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