help with controlling a form using a procedure in a module!

dholpower

New member
Joined
Mar 7, 2007
Messages
1
Programming Experience
Beginner
Hi all im new to vb.net I have created a module and I am trying to create a procedure inside the module to control certain form properties such as centring the forms on the users screen on runtime.

Im not to sure which procedure to use i.e. function procedure or sub procedure. Im pretty sure it the sub procedure

here is my code


Module centreform
'create a sub
Sub centreform(ByVal FormName As Form)
Me.Enabled.CenterToScreen()
End Sub
End Module

I know that this can be done on form load by just adding
Me.Enabled.CenterToScreen() to form load but i want to do it the module way.

when i use this code it says me is not valid in a module
any help would be greatly appreciated
 
Hey dholpower,

I'm on VS 2003, but here's something that may help (idea wise) until someone else comes along with a better solution for what you are trying to do.

Calling the procedure from Form1
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        CenterMyForms("frm2")

 End Sub
Module
VB.NET:
Module Module1

    Friend frm2 As Form2

    Sub CenterMyForms(ByVal formName As String)

        Select Case formName
            Case "frm2"
                If frm2 Is Nothing Then
                    frm2 = New Form2
                    frm2.StartPosition = FormStartPosition.CenterScreen
                    frm2.Show()
                Else
                    ' Form already exists, and needs to be re-positioned.
                    frm2.Left = CInt((CInt(Screen.PrimaryScreen.WorkingArea.Width) - frm2.Width) / 2)
                    frm2.Top = CInt((CInt(Screen.PrimaryScreen.WorkingArea.Height) - frm2.Height) / 2)
                    frm2.BringToFront()
                End If
            Case "frm3"
                '...
        End Select

    End Sub
End Module
 
VB.NET:
Sub centreform(ByVal theForm As Form)
    theForm.CenterToScreen()
End Sub
VB.NET:
themodule.centreform(Me)
 
Back
Top