Which button was clicked to open form

后端 未结 2 1432
野趣味
野趣味 2021-01-25 18:02

I have a form that loads from a click of any of three buttons (Add, Modify or Delete). When the form loads there is a \'Confirm\' button which will perform a task depending on w

相关标签:
2条回答
  • 2021-01-25 18:55

    Well suppose to define at the global level an enum like this

    Public Enum CommandAction
        Create
        Modify 
        Delete
    End Enum
    

    Now in the code used to launch your second form to execute the Add command, you could write code like this (of course you repeat the same but varying the CommandAction in the other buttons).

    Dim myFormInstance = new MyForm(CommandAction.Create)
    myFormInstance.ShowDialog()
    

    Finally, add a specfic constructor for your second form (MyForm in this example). A constructor that receives and saves for future usage a CommandAction

    Public Class MyForm
        Dim cmd as CommandAction
    
        Public Sub New(command as CommandAction )
             InitializeComponent()
             cmd = command
        End Sub
        Public Sub New()
             InitializeComponent()
             cmd = CommandAction.Create ' Set a default'
        End Sub
    End Class
    

    Now in the code where you need to decide which kind of action to execute, just look at the value of the global cmd variable and execute the appropriate block of code

    NOTE Adding a specific constructor to a form class requires the explicit presence of the standard empty constructor.

    0 讨论(0)
  • 2021-01-25 19:00

    first put a hidden field with some name like "clicked". Make a javascript function with one parameter to put values in to the hidden field. Call the function on click of every button but set some specific value for each button. In this way you will be able to run right code for each button on submit. If not understand then do tell me, i'll help you in the code.

    0 讨论(0)
提交回复
热议问题