none
Open Form Problem RRS feed

  • Question

  • Hi all,

    i had made a project that has 4 forms, and one class which is as the following:

    Public Class cMyButton
        Inherits Button
    
        Dim m_Form As Form
        Public Property FormToOpen As Form
            Set(ByVal value As Form)
                m_Form = value
            End Set
            Get
                Return m_Form
            End Get
        End Property
    
    
        Private Sub cMyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
            m_Form.ShowDialog()
        End Sub
    End Class

    when i drag the cMyButton to the stage (i.e. Form1), and go to the properties window\FormToOpen property, i do not find the rest of forms listed, only Form1.

     i want this list to list all the forms in the project, what can i do?


    Monday, October 15, 2018 4:22 AM

Answers

  • Hello,

    In your case as a work around you can create enum and pass enum value on button click to create instance

    see for your reference

    Public Class cMyButton
        Inherits Button
        Public Enum FormName
            Form1
            Form2
            Form3
        End Enum
        Dim m_Form As FormName
        Public Property FormToOpen As FormName
            Set(ByVal value As FormName)
                m_Form = value
            End Set
            Get
                Return m_Form
            End Get
        End Property
        Private Sub cMyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
            System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(System.Reflection.Assembly.GetEntryAssembly().GetName().Name & "." & m_Form.ToString()).show()
        End Sub
    End Class

    Monday, October 15, 2018 7:27 AM

All replies

  • Hello,

    In your case as a work around you can create enum and pass enum value on button click to create instance

    see for your reference

    Public Class cMyButton
        Inherits Button
        Public Enum FormName
            Form1
            Form2
            Form3
        End Enum
        Dim m_Form As FormName
        Public Property FormToOpen As FormName
            Set(ByVal value As FormName)
                m_Form = value
            End Set
            Get
                Return m_Form
            End Get
        End Property
        Private Sub cMyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
            System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(System.Reflection.Assembly.GetEntryAssembly().GetName().Name & "." & m_Form.ToString()).show()
        End Sub
    End Class

    Monday, October 15, 2018 7:27 AM
  • Thank you very much for your answer

    but when i make my control as a DLL file, i can not control the Enum to add/remove forms or rename it as i need.

    but really for now, i found the solution

    thank you again.

    Thursday, October 18, 2018 1:17 AM
  • Hi,

    We appreciate that you shared your solution with us. Please mark the post(s) that helped you as the answer.

    Best Regards,

    Alex


    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, October 18, 2018 3:01 AM