フォームの位置をデスクトップ座標で変更する
スポンサーリンク
VB6 では、Win32API の SystemParametersInfo 関数からワークエリアを取得します。General で SystemParametersInfo 関数の宣言をしておいてください。
サンプルコード
以下にサンプルコードを示します。
VB6.0 以前
Option Explicit ' SystemParametersInfo 関数 Private Declare Function SystemParametersInfo Lib "USER32.DLL" Alias "SystemParametersInfoA" ( _ ByVal uAction As Long, _ ByVal uParam As Long, _ ByRef lpvParam As Any, _ ByVal fuWinIni As Long _ ) As Long ' Rectangle 構造体 Private Type Rectangle Left As Long Top As Long Width As Long Height As Long End Type ' ワークエリアを取得する Private Const SPI_GETWORKAREA As Long = 48
VB6.0 以前
' Rectangle 構造体を宣言する
Dim tRectangle As Rectangle
' ワークエリアを取得する
Call SystemParametersInfo(SPI_GETWORKAREA, ByVal 0&, tRectangle, ByVal 0&)
' tRectangle を省略する
With tRectangle
' ピクセルから Twip に変換する
.Left = .Left * Screen.TwipsPerPixelX
.Width = .Width * Screen.TwipsPerPixelX
.Top = .Top * Screen.TwipsPerPixelY
.Height = .Height * Screen.TwipsPerPixelY
' ワークエリアの中央に表示する
Call Me.Move((.Width - .Left - Me.Width) \ 2, (.Height - .Top - Me.Height) \ 2)
' ワークエリアいっぱいに表示する場合
Call Me.Move(.Left, .Top, .Width, .Height)
End With
関連するリファレンス
準備中です。
