Results 1 to 4 of 4

Thread: each object displaying it's name in a textbox when clicked on - possible?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121

    each object displaying it's name in a textbox when clicked on - possible?

    hi. i'm having a problem. when the user clicks on any object in my program i want it's name to appear in a certain textbox. the following code will do it only if i set ALL the objects as handles. this hardly seems feasible. does anyone know of an easier way? here's what i have:

    Code:
    Private Sub Object_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeaveCoverRdo.Click, SnowCompleteRdo.Click, SnowPartiallyRdo.Click, TooHighRdo.Click, PercVisCmb.Click, etc, etc, etc.....
    
            CustTxt.Text = sender.Text
    End Sub

  2. #2
    Member
    Join Date
    Apr 2002
    Posts
    36
    What kind of objects are these?

    BTW, try this, in the object's (im assuming stuff like Pictureboxes, Buttons, etc.) Click procedure type this:

    Private Sub MyObject1_Click()

    textbox.text = "MyObject1"

    End Sub


    So rather than making it automatically detect the object's name, just cheat and make it send it directly :-)

    That way for all the objects you just edit what it says in the quotes to reflect all those object's names.

  3. #3
    Tygur
    Guest
    You could do something like this:
    Code:
        Sub SetGenericClick()
            Dim Ctl As Control
            For Each Ctl In Controls
                AddHandler Ctl.Click, AddressOf GenericClick
            Next
        End Sub
    
        Sub GenericClick(ByVal sender As Object, ByVal e As System.EventArgs)
            CustTxt.Text = sender.text
        End Sub
    Just make sure that SetGenericClick gets run when the form starts.

    Note that, according to the help files, "you should not use both WithEvents and AddHandler with the same event". By WithEvents, they mean the Handles keyword.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Posts
    121
    SetGenericClick() is called when the form loads, but when i click something the AddHandler statement doesn't seem to call up GenericClick(), so i'm still not seeing anything in my textox. it doesn't seem like "For Each Ctl In Controls" is cycling through my controls.

    I will try playing w/ it some more, but let me know if you have any other suggestions.

    Thanks for the help,
    Brad

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