Positioning
Form.StartPosition
Enables you to set the start position of a form at run-time
This property should be set before the form is shown.
In 3.5 this property works with both .Show and .ShowDialog
FormStartPosition Enumeration
WindowsDefaultLocation (default) | Form is positioned at the windows default location and has the dimensions specified in the forms size |
WindowsDefaultBounds | Form is positioned at the windows default location and has the bounds determined by windows default |
CenterParent | Form is centered within the bounds of its parent form |
best for modal / ShowDialog | |
CenterScreen | Form is centered on the current display with dimensions specified in the forms size |
Manual | Position is determined by the Location property |
Me.Location = Drawing.Point |
Possible Scenarios
1) Modal, on top of all windows
.TopMost = True
2) Modal, on top of that application
.StartPosition = CenterParent
.ShowDialog
2) Modeless, on top of that application
.StartPosition = Manual
.Show(gFormNativeWindow)
System.Windows.Forms.Screen.PrimaryScreen
this gets the primary screen
WorkingArea.Height - gets the height of the display excluding the taskbar.
Load Event
This event will be generated for you by double clicking anywhere on the form.
Private Sub frmMain_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If App_RegSaveFormPositionRead() = True Then
Me.Location = New System.Drawing.Point(clsRegistry.App_RegFormPositionLeftRead(gsREGISTRY_APPNAME), _
clsRegistry.App_RegFormPositionTopRead(gsREGISTRY_APPNAME))
Me.Size = New System.Drawing.Size(clsRegistry.App_RegFormPositionWidthRead(gsREGISTRY_APPNAME, _
giDEFAULT_FORMWIDTH), _
clsRegistry.App_RegFormPositionHeightRead(gsREGISTRY_APPNAME, _
giDEFAULT_FORMHEIGHT))
End If
End Sub
Unload Event
#Region " Windows Form Designer generated code "
Inside this region is a Dispose generated subroutine.
Add the call to the Form_Load subroutine at the top of this subroutine.
Protected Overloads Overrides Sub Dispose(ByVal bdisposing As Boolean)
Call frmMain_Close()
If bdisposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(bdisposing)
End Sub
Create the following private subroutine below the Form_Load event
Private Sub frmMain_Close()
If App_RegSaveFormPositionRead() = True Then
With gfrmMAINFORM.DesktopBounds
Call clsRegistry.App_RegFormPositionLeftSave(gsREGISTRY_APPNAME, .Left)
Call clsRegistry.App_RegFormPositionTopSave(gsREGISTRY_APPNAME, .Top)
Call clsRegistry.App_RegFormPositionWidthSave(gsREGISTRY_APPNAME, .Width)
Call clsRegistry.App_RegFormPositionHeightSave(gsREGISTRY_APPNAME, .Height)
End With
End If
End Sub
AppRegistry
Public Function App_RegSaveFormPositionRead() As Boolean
App_RegSaveFormPositionRead = _
CBool(App_RegistryRead("Options", "Save Form Position", CStr(False)))
End Function
Public Sub App_RegSaveFormPositionSave(ByVal bValue As Boolean)
Call App_RegistrySave("Options", "Save Form Position", CStr(bValue))
End Sub
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext