none
how do iget an activeform control name in Public Function vb.net2008 RRS feed

  • Question

  • i need to get a clicked control name on active form something like

    Dim edit As Control = Form.ActiveForm.Controls.Find(sender, Control)

    hope some one help me

    that's my code

    ihave  tried DirectCast

    Public Function regfunctionsetrec()
    Dim strHostName As String
    Dim strIPAddress As String
    
    strHostName = System.Net.Dns.GetHostName()
    strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
    
    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Dim MYFormName As String = Form.ActiveForm.Name
    Dim id As String = " / " + index_ar.ToolStripLabel2.Text
    Dim id1 As String = "" '" / " + index_en.ToolStripLabel2.Text
    Dim ctrlName As String = DirectCast(Sender, Control).Name
    

    Sunday, July 16, 2017 10:33 PM

All replies

  • Use ActiveControl. That works unless say the user clicked on a control such as a label which does not get focus.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, July 16, 2017 10:39 PM
    Moderator
  • i need to get a clicked control name on active form something like

    If you have a 'sender' variable then you have the control.   You haven't indicated where that code is being executed.  If it is in a control event handler (which the 'sender' implies it is) then you already have the control.  You only need to pass the 'sender' variable in the call to the function.

    Sunday, July 16, 2017 11:00 PM
  • feras29:

    Do you mean you wanna catch the clicked control name?

    If yes, why DON'T you catch the event such as "Click" and do convert such as:

    Private Sub Button_Click(ByVal sender As Object, ByVal args As EventArgs) Handles Button1.Click
    
         Dim c As Control = sender
    
         c.Name……
    
    End Sub

    ASP.NET Forum
    StackOverFlow
    FreeRice Donate
    Issues to report



    Monday, July 17, 2017 3:42 AM