JC,

It's not quite an elegant solution, but you should be able to make it work through 
reflection.

[C#]
private void OnMenuItemClick(object sender, EventArgs e) {
    Type myFormType = myForm.GetType();
    string name;
    
    foreach (FieldInfo field in myFormType.GetFields()) {
        if (field.GetValue(myForm) == sender) {
            name = field.Name;
            break;
        }
    }
}

[VB]
Private Sub OnMenuItemClick(sender As Object, e As EventArgs)
    Dim myFormType As Type = myForm.GetType()
    Dim field As FieldInfo
    Dim name As String

    For Each field In myFormType.GetFields()
        If field.GetValue(myForm) Is sender Then
            name = field.Name
            Exit For
        End If
    Next
End Sub

This assumes that myForm contains a reference to your form object and that the System 
and System.Reflection namespaces are correctly imported. When the OnMenuItemClick 
method is added to the event handlers for the Click event of the MenuItem, the name of 
the field that holds the reference to the clicked MenuItem will be assigned to the 
variable name.

HTH,

Stefan

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to