控制面板中两行之间的间距 [英] Control the space between two lines in Panel

查看:96
本文介绍了控制面板中两行之间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试创建类似于Windows消息框的自己的消息框.

我正在使用MessageBox窗体上的面板来显示用户消息.

我正在使用MS Gothic作为大小为10的Font类型.Font的unit属性使用点.

显示消息时,发现两行之间的间隔很小.

我想增加空间,即要在程序中对其进行控制.

VB.Net中是否有任何属性可以实现以上目的.


感谢任何想法.


问候,

Vijay.

Hi,

I am trying to create my own Message box similar to Windows message box.

I am using a panel on the MessageBox form to display the user message.

I am using MS Gothic as the Font type with size 10.Using point for the unit property of Font.

When I display the message, I found that the space between two line is very small.

I want to increase the space i.e I want to control it in the program.

Is there any property in VB.Net to achieve the above.


Appreciate any idea.


Regards,

Vijay.

推荐答案

请参阅我对问题的评论:需要澄清.
如果要在不同控件的文本之间留一个间距,这很简单:只需在它们之间插入一些间隔Panel,它们的System.Windows.Controls.Dock属性值应相同,即System.Windows.Forms.TopSystem.Windows.Forms.Bottom:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.forms.dockstyle.aspx [ ^ ].

原则上,可以在更复杂的情况下使用此技术,请参见下文.

因此,如果您想增加在显示的带有结尾行字符或自动换行符的字符串中的间距,该怎么办?这非常困难,因为System.Drawing.CanvasSystem.Drawing.Font都不具有适当的属性(但根据其文档,本机GDI +具有).一种方法是:您可以将字符串解析为单独的行,并在OnPaint方法中的某些自定义控件中分别渲染每行.如果渲染的换行符仅基于行尾字符,则这种解析很容易,但是使用自动自动换行非常困难.在这种情况下,您需要测量每条线的宽度:
http://msdn.microsoft.com/en-us/library/system. drawing.graphics.measurestring.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/7sy6awsb.aspx [ ^ ].

这里最大的问题是这些方法返回的宽度不是很准确,因为它不需要提示( http://en.wikipedia.org/wiki/Hinting [ ^ ]).

现在,作为替代方案,您可以使用只读System.Windows.Forms.RichTextBox,在其中可以设置段落的行间距:
http://msdn.microsoft.com/en-us/library/system. windows.forms.richtextbox.aspx [ ^ ].

这会简单得多.而选择它的事实仅是一件好事:您可以允许客户将文本复制到剪贴板,例如,发送问题报告.经验表明,几乎所有客户实际上都无法写出他们在问题报告中在屏幕上看到的内容.

—SA
Please see my comments to the question: some clarification is needed.

If you want to make a spacing between texts of different controls, this is trivial: just insert some spacer Panel between them, having the same value of System.Windows.Controls.Dock property, either System.Windows.Forms.Top or System.Windows.Forms.Bottom:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx[^].

In principle, you can use this technique in a more complex case, see below.

So, what to do if you want to increase spacing in the rendered string shown with end line characters or auto word wrapping? This is pretty difficult, because neither System.Drawing.Canvas nor System.Drawing.Font has an appropriate property (but native GDI+ has, according to its documentation). One approach is this: you can parse the string into separate lines and render each line separately in some custom control in your OnPaint method. Such parsing is easy if the rendered line breaks are based only on end-of-line characters, but pretty difficult it the automatic word wrapping is used. In this case, you would need to measure each line''s width:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx[^],
http://msdn.microsoft.com/en-us/library/7sy6awsb.aspx[^].

The big problem here is that the width returned by these methods is not very accurate because it does not take hinting (http://en.wikipedia.org/wiki/Hinting[^]) in account.

Now, for the alternative, you can use read-only System.Windows.Forms.RichTextBox where you can set a paragraphs line spacing:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx[^].

This would be much simpler; and the fact it''s selectable is only for good: you can allow your customers to copy the text to clipboard, for example, to send an issue report. Experience shows that nearly all customers are physically unable to write what they could see on screen in an issue report.

—SA


这篇关于控制面板中两行之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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