The following VB.NET Code Snippet is used to dynamically align the form to the center of the window, based on the the end users screen resolution.
Sub Center_Form()
Dim maxwidth As Integer = Screen.PrimaryScreen.WorkingArea.Size.Width
Dim left As Integer
Dim top As Integer
'Remove 10% top part of window
Dim maxheight As Integer = Screen.PrimaryScreen.WorkingArea.Size.Height - Screen.PrimaryScreen.WorkingArea.Size.Height * 0.1
left = (maxwidth - Me.Width) / 2
top = ((maxheight - Me.Height) / 2)
Me.Location = New Point(left, top)
End Sub
Call the function Center_Form in the Form_Load event of the form.
Private Sub DataForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
‘Center display
Center_Form()
End Sub
The following VB.NET Code Snippet is used to maximize the form.
Private Sub Maximize()
Me.WindowState = FormWindowState.Maximized
End Sub
The following VB.NET Code Snippet is used to minimize the form.
Private Sub Minimize()
<B>Me.WindowState = FormWindowState.Minimized</B>
End Sub
hi
ReplyDeleteDo i need to add any namespaces?
if so please tel me
Hi,
ReplyDeleteThere is no need to add any namespace to use the above code snippet.
hi
ReplyDeletei added the above code in mater page
I am getting error at this.Width
do i need to add any namespace