vba Visual Basic 中的屏幕尺寸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7844171/
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-11 14:19:12  来源:igfitidea点击:

Screen Dimensions in Visual Basic

vbascreen-size

提问by Monkeyanator

How can you access the dimensions of the screen in Visual Basic? I have looked online and it says to use Screen.width and Screen.length, but it doesn't recognize those properties... any tips?

如何在 Visual Basic 中访问屏幕的尺寸?我在网上看了一下,它说要使用 Screen.width 和 Screen.length,但它不能识别这些属性......有什么提示吗?

回答by Boann

In VB you can use Screen.Widthand Screen.Height. They're not in VBA but you can use an API call instead. Add these declarations:

在 VB 中,您可以使用Screen.WidthScreen.Height。它们不在 VBA 中,但您可以改用 API 调用。添加这些声明:

Public Declare Function GetSystemMetrics Lib "user32.dll" (ByVal index As Long) As Long
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

Then use like so:

然后像这样使用:

MsgBox GetSystemMetrics(SM_CXSCREEN) & "x" & GetSystemMetrics(SM_CYSCREEN)