We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,521 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Using sender

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.

3
Contributors
3
Replies
5 Hours
Discussion Span
4 Months Ago
Last Updated
6
Views
Question
Answered
tinstaafl
Nearly a Posting Virtuoso
1,470 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14

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.

TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 149
Skill Endorsements: 13

k thx

tinstaafl
Nearly a Posting Virtuoso
1,470 posts since Jun 2010
Reputation Points: 429
Solved Threads: 262
Skill Endorsements: 14
Question Answered as of 4 Months Ago by TnTinMN

And it's not that much extra typing to do

DirectCast(sender,TextBox).SelectAll()
Reverend Jim
Illigitimae non carborundum
Moderator
3,740 posts since Aug 2010
Reputation Points: 585
Solved Threads: 469
Skill Endorsements: 33

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0623 seconds using 2.65MB