none
change Form properti from sub / function

    Question

  • Dear All

    PLs Help MeI want changer property all my form from  sub/function

    Example

    My Procedure

    Module TestForm
        Public Sub gsubSetRezise(ByRef vForm As System.Windows.Forms.Form)
            vForm.Left = 0
            vForm.Top = 0
            vForm.Width = 500
            vForm.Height = 400

             MsgBox("width on gsubSetRezise " & vForm.name &" is " & vForm.Width) 

            Exit Sub

        End Sub
    End Module


    ON my form name is test001

    Public Class test01

        Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim cFrom As System.Windows.Forms.Form
            cForm = New test01

           MsgBox("width Before " & Me.Width)      

            Call gsubSetRezise(cForm)

            MsgBox("wdith After " & Me.Width) 

        End Sub

     End Class


    Result  my program

    width Before 40

    width on gsubSetRezise test001 is 500 

    width After 40

    Why form test01 with not change

    Sunday, February 19, 2017 3:14 AM

All replies

  • Hi,

    instead of creating a new form (new test01) use the current instance

      Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim cFrom As System.Windows.Forms.Form
            cForm = Me 'Me is a keyword, a reference to the current instance of the current class
    
           MsgBox("width Before " & Me.Width)      
    
            Call gsubSetRezise(cForm)
    
            MsgBox("wdith After " & Me.Width) 
    
        End Sub

    or just call the sub with "Me" as parameter:

       Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
           MsgBox("width Before " & Me.Width)      
    
            Call gsubSetRezise(Me)
    
            MsgBox("wdith After " & Me.Width) 
    
        End Sub

    Regards,

      Thorsten


    Sunday, February 19, 2017 4:28 AM
  • Hi wiyono suparno,

    Is the reply from Thorsten helpful to you?

    Please feel free to let us know if you have any other issue.

    Best regards,

    Fletch


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 23, 2017 7:17 AM