有没有办法在 vb 或 vba 中对齐消息框中的文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9131055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:31:44  来源:igfitidea点击:

Is there any way to align text in message box in vb or vba?

vbavb6vbscriptmessagebox

提问by Pratik Gujarathi

Is there any way to align text into the center in msgboxin VB or VBA? Does VB have any functionality to do the same?

有没有办法msgbox在VB或VBA中将文本对齐到中心?VB 是否有任何功能可以做同样的事情?

回答by Deanna

No. The MsgBox()function is simply a wrapper for the Windows MessageBox()function and as such has no stylistic control over the dialog beyond the icon.

不可以。该MsgBox()函数只是 WindowsMessageBox()函数的一个包装器,因此除了图标之外没有对对话框的风格控制。

If you want to change it any further than this, you will need to create your own window and show that instead.

如果您想进一步更改它,您将需要创建自己的窗口并显示它。

On Windows Vista+ you can use TaskDialogsthat allow a lot more control.

在 Windows Vista+ 上,您可以使用允许更多控制的任务对话框

回答by Omar Luján

no, but you can cheat by using spaces.

不,但您可以使用空格作弊。

msgbox("                your message")

回答by Fionnuala

VBA

VBA

Some notes: http://access.mvps.org/access/bugs/bugs0035.htmAND http://www.tek-tips.com/viewthread.cfm?qid=435428However, it is not so difficult to build your own message box, which solves all your problems.

一些注意事项:http: //access.mvps.org/access/bugs/bugs0035.htmhttp://www.tek-tips.com/viewthread.cfm?qid=435428但是,构建您的自己的消息框,解决您所有的问题。

回答by klausnrooster

When you are building your strings you could pad them at the beginning and end with spaces to achieve a target length. If you're using excel the worksheet function rept is handy for this.

在构建字符串时,您可以在开头和结尾填充空格以达到目标长度。如果您使用的是 excel,工作表函数 rept 对此很方便。

function pad_n_center(byval mystring as string, lenmax as integer) as string
    dim pad_by as integer
    dim pad as string
    pad_by = (lenmax - len(mystring))/2
    'some more code to finesse that?
    pad = worksheetfunction.rept(" ",pad_by)
    pad_n_center = pad & mystring & pad
end function

As mentioned before if the msgbox still doesn't look good you can use textbox shape object (or other objects) to get the desired effect.

如前所述,如果 msgbox 仍然不好看,您可以使用文本框形状对象(或其他对象)来获得所需的效果。