Results 1 to 3 of 3

Thread: Sender Parameter - Name of Control

  1. #1

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Sender Parameter - Name of Control

    When coding the equivelent of control arrays in vb.Net, I have been using event functions with multiple Handles parameters.

    ie,
    VB Code:
    1. Private Sub mnuFileModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileModify.Click, mnuFileInsert.Click, mnuFileDelete.Click

    My question then is how to detect from the Sender parameter the name of the individual control.

    I can use the following code to extract various properties - ie, the "Text" property - but I would prefer to actually refer to the Control Name (mnuFileInsert etc.)

    VB Code:
    1. Dim mnuX As MenuItem
    2.       mnuX = CType(sender, MenuItem)
    3.       if mnuX.Text.StartsWith("Insert" Then
    4. ...
    5.       End If

    Can anyone help?

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    sender.Name
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    One of our standards here is to set "Option Strict On"
    and Sender.Name doesn't work (it uses late binding).

    I thought if I converted it to the menuitem class (or any other control class), there would be a Name property available - but there doesnt seem to be one.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width