CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    27

    CType(Sender help

    im trying to change the .text property of whatever label is clicked.. to me this makes perfect sense and should run.

    Please tell me whats wrong?
    Code:
     Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click, Label3.Click, Label4.Click, Label5.Click, Label6.Click, Label7.Click, Label8.Click, Label9.Click, Label10.Click
            With CType(sender, Label).Name
                .text = XOval
            End With
        End Sub

  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: CType(Sender help

    Code:
    CType(sender, Label).Name
    Think about this line for a second. How does this makes perfect sense?
    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    Mar 2005
    Posts
    16

    Re: CType(Sender help

    Quote Originally Posted by |2eM!x
    Code:
    With CType(sender, Label).Name
    This line should be changed to:

    Code:
    With CType(sender, Label)
    Reason being is obvious. In your code you are saying: "With the object reference returned by the 'Name' property of the Label reference returned by the CType cast on the sender object..." - In other words, you are "Withing" a String object reference, which has no "Text" property.

    The correction I gave would be described as this: "With the object reference returned by the CType cast on the sender object..." - Which would be correct as it returns a Label object reference which does have a "Text" property.

    Hope that helps. Was probably just an oversight on your part.

  4. #4
    Join Date
    May 2005
    Posts
    27

    Re: CType(Sender help

    Yes thanks, im new to .net, so that made perfect sense to me..

    I thought what i had returned which label i clicked on, but alas now i understand it does not. Thanks

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

Featured