|
|
Title | Position a popup form on a particular area on its parent form in Visual Basic .NET |
Description | This example shows how to position a popup form on a particular area on its parent form in Visual Basic .NET. |
Keywords | popup, form, position, VB.NET |
Categories | Controls, VB.NET |
|
|
Thanks to Gary Winey (j2associatesNO_SPAM@yahoo.com).
The Popup form uses the following code to position itself in the upper right, upper middle, lower left, etc. part of its parent form.
|
|
Private Sub SetupValues(ByVal location As String, _
ByVal parent As Form, _
ByVal lastLocation As Point, _
ByVal lastSize As Size)
Dim x, y, width, clientWidth, height, clientHeight, _
border, titleHeight As Integer
With parent
With .Location
x = .X
y = .Y
End With
With .ClientSize
clientWidth = .Width
clientHeight = .Height
End With
With .Size
width = .Width
height = .Height
End With
border = Math.Abs((width - clientWidth) \ 2)
titleHeight = height - clientHeight - border
End With
Dim point As New Point(x, y)
point.X += border
point.Y += titleHeight
Dim size As Size
Me.StartPosition = FormStartPosition.Manual
If lastLocation.Equals(point.Empty) Then
Select Case location.Trim.ToLower
Case "ul"
' Do nothing
Case "ml"
point.Y += ((clientHeight - Me.Height) \ 2)
Case "ll"
point.Y += (clientHeight - Me.Height)
Case "um"
point.X += ((clientWidth - Me.Width) \ 2)
Case "mm"
point.X += ((clientWidth - Me.Width) \ 2)
point.Y += ((clientHeight - Me.Height) \ 2)
Case "lm"
point.X += ((clientWidth - Me.Width) \ 2)
point.Y += (clientHeight - Me.Height)
Case "ur"
point.X += (clientWidth - Me.Width)
Case "mr"
point.X += (clientWidth - Me.Width)
point.Y += ((clientHeight - Me.Height) \ 2)
Case "lr"
point.X += (clientWidth - Me.Width)
point.Y += (clientHeight - Me.Height)
End Select
size = New Size(300, 300)
Else
point = lastLocation
size = lastSize
End If
Me.Location = point
Me.Size = size
End Sub 'SetupValues
|
|
|
|
|
|