1,105,221 Community Members

Using sender

Member Avatar
tinstaafl
Postaholic
2,009 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 400 [?]
Skill Endorsements: 35 [?]
 
0
 

A curious thing, is there a reason that you can't declare sender as a specific type? For instance, if you had a number of textboxes and you wanted each one to select all it's text when you click on it could you use :

    Public Sub TextBox_Click(ByVal sender As TextBox, ByVal e As System.EventArgs)
        sender.SelectAll()
    End Sub

and add it as the Click Event handler to each textbox.

It seems kind of obvious to me, and it does work. But I'm wondering if there is something deep inside visual studio that'll get screwed up.

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

To make that work you need to have Option Strict Off which is something I personally do not care for, but to each their own.

You are forcing a narrowing implicit conversion on the method signature (delegate). Based on Variance in Delegates (C# and Visual Basic) I believe you are safe.

Member Avatar
tinstaafl
Postaholic
2,009 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 400 [?]
Skill Endorsements: 35 [?]
 
0
 

k thx

Question Answered as of 1 Year Ago by TnTinMN
Member Avatar
Reverend Jim
Noli mentula
5,393 posts since Aug 2010
Reputation Points: 744 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

And it's not that much extra typing to do

DirectCast(sender,TextBox).SelectAll()
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: