General Development

Getting Object information using mousehover – DeathFox

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
Apparently, I have several buttons on a form. To have an efficient code, I would like to just get the object name if I mousehover it rather than make a mousehover procedure for every button. So how do I do it? I tried GetChildAtPoint but it didn't work. HELP.
Calin

Member

Posts: 358
From: Moldova
Registered: 12-04-2006
You need to register a MouseHover event for that and every other button. I don't think there's another way to do it (I might be wrong, but I don't see a problem with registering an event for each button)

------------------
Nanostorm

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
There are about 30 buttons
Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
How about this code:

// php:

$tc = "JavaScript:fieldHover($x,$y)";

<td width=\"24\" height=\"24\" onhower=\"$tc\">field</td>

// javascript:

<script language="JavaScript">

function fieldHover(x,y)
{
}

So with php you can make a for loop that generates the fields with required javascript "onhover"(s)


I hope that helps...

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

[This message has been edited by jari (edited August 02, 2007).]

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
Thanks, I'm using VB.NET . And I need a code that will show in a msgbox the name of the object the mouse cursor is on. Like when I hover on top of button1, a msg box will appear and say "You are on button1"
Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Oh! I thought you were making a html form.
Sorry I dont know VB...

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

Calin

Member

Posts: 358
From: Moldova
Registered: 12-04-2006
You could try asking in this .Net forum:

http://groups.google.com/group/DotNetDevelopment

------------------
Nanostorm

christo
Member

Posts: 75
From:
Registered: 07-12-2004
In VB.Net you can use the same code for multiple events. Try looking for the events button in the property window of the controls you want to mouse over and just set the mouse over event to the same sub procedure. this may or may not be what you were looking for but it makes it so you don't have to rewrite the code over and over.
DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
But that would take >30 lines of code. I'm looking for a
Get Object at (MousePosition()) type of function.
Jari

Member

Posts: 1471
From: Helsinki, Finland
Registered: 03-11-2005
Would it be possible to do something like this in VB:

loop arrayOfControls
control.onhoverCallback = callbackfn

then the callback fn:

callbackfn(thiscontrol)
do something with this control

------------------
Psa 32:5 I acknowledged my sin unto thee, and mine iniquity have I not hid. I said, I will confess my transgressions unto the LORD; and thou forgavest the iniquity of my sin. Selah.

[VoHW] (Help needed) [Blog] (Contact) - Truedisciple (mp3)

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
For a .NET form, if I was trying to keep the lines of code down, I would probably do something like this.

On each button/item, put my help text in the tag of each button.

Then, create a single method that every button's hover event points to (shift-select all of the buttons at once, then point them to this event handler that you create):

Private Sub Generic_MouseHover(ByVal sender As System.Object, ByVal e_
As System.EventArgs)
StatusBar1.Text = sender.tag.ToString() ' Or however you want to handle the mouseover thing
End Sub

Sorry, I'm a C# guy, not a VB.Net guy, but that's some of how I would do it. You might have to cast the sender object to be a windows form object in order to get access to its tag property (though after you cast, don't forget to check to make sure that it's still valid).

Sorry I can't write you more code -- I could do this all day in C#, but I just don't know VB.Net syntax.

--clint

jestermax

Member

Posts: 1064
From: Ontario, Canada
Registered: 06-21-2006
i'm going from old vb6 code here... but can't you use a control array and just grab the index from the event?

------------------
Visit my portfolio (and check out my projects):
www.JestermaxStudios.com

DeathFox
Member

Posts: 57
From:
Registered: 04-25-2006
Thanks. But the code above just points to the main form, not the individual objects.