How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move
How to get the conrol name on Mouse move How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
Go Back  Xtreme Visual Basic Talk > > > How to get the conrol name on Mouse move


Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2014, 09:07 PM
waseemsz waseemsz is offline
Freshman
 
Join Date: Jan 2011
Location: Halifax NS Canada
Posts: 29
Question How to get the conrol name on Mouse move


Hi Folks, I have an application which has multiple controls on it (buttons, textboxs etc). I am trying to get the control name when mouse is brought over any control. I tried few codes but no joy. I would highly appreciate if anyone can help me with that.
Thanks,
Reply With Quote
  #2  
Old 10-23-2014, 07:59 AM
Cerian Knight's Avatar
Cerian KnightHow to get the conrol name on Mouse move Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

It should be possible through using System.Reflection, though not something that is required for 'mainstream' programming.

You can also use System.Reflection to go the other direction... find an object (e.g. Control) by its name.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 10-23-2014, 09:34 AM
waseemsz waseemsz is offline
Freshman
 
Join Date: Jan 2011
Location: Halifax NS Canada
Posts: 29
Default

Thanks for your kind help. That would be greatly appreciated if you can give me the code for this scenario as I am not familiar with System.Reflection. Thanks
Reply With Quote
  #4  
Old 10-23-2014, 10:17 AM
Cerian Knight's Avatar
Cerian KnightHow to get the conrol name on Mouse move Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

Without going advanced, have you tried this type of simple code:
Code:
Public Class Form1
    'Add two buttons and a textbox to a form
    Private Sub Button1_MouseMove(sender As Object, e As MouseEventArgs) Handles Button1.MouseMove, Button2.MouseMove, TextBox1.MouseMove
        TextBox1.Text = sender.Name
    End Sub
End Class
Adding handlers at runtime (e.g., using AddHandler statement) might be possible through enumeration of controls, but I'm not familiar with doing so, so not sure.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 10-23-2014 at 10:27 AM.
Reply With Quote
  #5  
Old 10-23-2014, 10:33 AM
waseemsz waseemsz is offline
Freshman
 
Join Date: Jan 2011
Location: Halifax NS Canada
Posts: 29
Default

I have already tried the above code but the problem is: if I have 100 controls on the form then I will need to write this code for each control mousemove event which is lots of code rewriting. I am simply looking for a a method which gives me control name when mouse is brought over any control. Thanks
Reply With Quote
  #6  
Old 10-23-2014, 11:24 AM
Cerian Knight's Avatar
Cerian KnightHow to get the conrol name on Mouse move Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

As you can see, doing it per the above example requires only one MouseMove event to service all 3 of the controls.

If you already have multiple MouseMove events, either add '{some property or variable} = sender.Name' to each MouseMove event or use Case selection (based on sender.Name) to process all MouseMove code within one event handler per the example (or use AddHandler to enumerate and automatically add all to the one event, if possible).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #7  
Old 10-23-2014, 12:14 PM
passel's Avatar
passelHow to get the conrol name on Mouse move passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

You also have the option to select all the controls you want in the Designer, then select the Event List in the Properties window go down to the event you want and double click on it.
The IDE will generate the even handler sub with handle clauses for all the controls selected, e.g.

Private Sub Button18_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles Label9.MouseMove, Label8.MouseMove, Label7.MouseMove, Label6.MouseMove, Label5.MouseMove, Label4.MouseMove, Label3.MouseMove, Label20.MouseMove, Label2.MouseMove, Label19.MouseMove, Label18.MouseMove, Label17.MouseMove, Label16.MouseMove, Label15.MouseMove, Label14.MouseMove, Label13.MouseMove, Label12.MouseMove, Label11.MouseMove, Label10.MouseMove, Label1.MouseMove, Button9.MouseMove, Button8.MouseMove, Button7.MouseMove, Button6.MouseMove, Button5.MouseMove, Button4.MouseMove, Button3.MouseMove, Button21.MouseMove, Button20.MouseMove, Button2.MouseMove, Button19.MouseMove, Button18.MouseMove, Button17.MouseMove, Button16.MouseMove, Button15.MouseMove, Button14.MouseMove, Button13.MouseMove, Button12.MouseMove, Button11.MouseMove, Button10.MouseMove

End Sub

It picks one of the control's name (in this case Button18 which was the Last selected, i.e. the reference control) for the method name, but you can rename that to something more general after it creates it.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #8  
Old 10-23-2014, 04:29 PM
waseemsz waseemsz is offline
Freshman
 
Join Date: Jan 2011
Location: Halifax NS Canada
Posts: 29
Default

Thanks guys. It works like a charm. I highly appreciate your kind help.
Regards,
Reply With Quote
  #9  
Old 10-26-2014, 09:10 PM
Amerigo's Avatar
Amerigo Amerigo is offline
Centurion
 
Join Date: Jan 2009
Location: USA
Posts: 175
Default

Edit by Moderator: New question split to new thread: Addhandler error with Toolstrip/Menustrip 'Buttons'
As for the OP, this works:
Code:
Form_Load... handles mybase.load
for each CTRL as control in me.controls
'if you wish to eliminate one or more specific controls, you can use if/then statements...
If CTRL isnot Panel1 and CTRL isnot TextBox1 then
addhandler CTRL.MouseEnter, AddressOf YourSub
End IF
Next
__________________
Amerigo

Last edited by Cerian Knight; 10-27-2014 at 12:02 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
 
How to get the conrol name on Mouse move
How to get the conrol name on Mouse move
 
-->