如何讓我的應用程式在螢屏中央打開?我知道如何使用 Form 應用程式,但我不知道如何使用控制臺,因為它的作業方式不同。
Console.Location = New Point((Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
(Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2)
Console.SetWindowPosition(0, 0)
uj5u.com熱心網友回復:
嘗試這個:
Public Shared Sub CenterConsole()
Dim hWin As IntPtr = GetConsoleWindow()
Dim rc As RECT
GetWindowRect(hWin, rc)
Dim scr As Screen = Screen.FromPoint(New Point(rc.left, rc.top))
Dim x As Integer = scr.WorkingArea.Left (scr.WorkingArea.Width - (rc.right - rc.left)) / 2
Dim y As Integer = scr.WorkingArea.Top (scr.WorkingArea.Height - (rc.bottom - rc.top)) / 2
MoveWindow(hWin, x, y, rc.right - rc.left, rc.bottom - rc.top, False)
End Sub
Private Structure RECT
Public left, top, right, bottom As Integer
End Structure
<DllImport("kernel32.dll", SetLastError:=True)>
Private Shared Function GetConsoleWindow() As IntPtr
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function GetWindowRect(ByVal hWnd As IntPtr, <Out> ByRef rc As RECT) As Boolean
<DllImport("user32.dll", SetLastError:=True)>
Private Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer, ByVal repaint As Boolean) As Boolean
當您想將控制臺視窗居中時,只需像這樣呼叫 CenterConsole 子:
CenterConsole()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/341378.html
標籤:网络
下一篇:每秒在VB控制臺中重復相同的操作
