フォームをデスクトップの任意の位置に表示させる
VB2005でフォームをデスクトップの任意の位置に表示させるには、以下の4つの要素が必要です。
- デスクトップの高さ(System.Windows.Forms.Screen.GetWorkingArea(Me).Height)
- デスクトップの幅(System.Windows.Forms.Screen.GetWorkingArea(Me).Width)
- フォームの高さ(Me.Size.Height)
- フォームの幅(Me.Size.Width)
この4つの要素の値がわかれば、上手く計算して座標を求めることができ、デスクトップの任意の位置に表示することができますね。
そして、表示するメソッドは、『SetDesktopLocation(幅,高さ)』を使用します。
Dim intDesktopHeight As Integer Dim intDesktopWidth As Integer Dim intFormHeight As Integer Dim intFormWidth As Integer intDesktopHeight = System.Windows.Forms.Screen.GetWorkingArea(Me).Height intDesktopWidth = System.Windows.Forms.Screen.GetWorkingArea(Me).Width intFormHeight = Me.Size.Height intFormWidth = Me.Size.Width 'デスクトップ左上 Me.SetDesktopLocation(0, 0) 'デスクトップ左下 Me.SetDesktopLocation(0, intDesktopHeight - intFormHeight) 'デスクトップ右上 Me.SetDesktopLocation(intDesktopWidth - intFormWidth, 0) 'デスクトップ右下 Me.SetDesktopLocation(intDesktopWidth - intFormWidth, intDesktopHeight - intFormHeight)