Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Obtaining control under mouse

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johnny Jensen - 14 Nov 2006 22:51 GMT
Hello Group

In the old days i'ev created a VB6 appl. that was able to obtain the
underlaying control under the mouse pointer. I would very much like to do
that in a C# application. I'll use VS2005 and .Net 2.0

I'll know of the solution to code each control for the mouse over event, but
I cant use that i this case.

Any one outthere with som examples?

Kind regards
Johnny Jensen
Michael C - 14 Nov 2006 23:35 GMT
> Hello Group
>
[quoted text clipped - 6 lines]
>
> Any one outthere with som examples?

interate through the controls collection and attach the mousemove event for
every control and then use Control.GetChildAtPoint in the event to find the
control the mouse it over.

Michael
Johnny Jensen - 15 Nov 2006 21:10 GMT
Hey Michael

Thanks for replying and it gave me some hint, but mabye i'am a bit slow
here.

Say that i'll have a label control on my form in the rectangle 20,20,120,36
on the forms mousemove event I read the x any y values to get the point, but
the secund i reach the label the forms mousemove no longer runs - now it is
the labels mousemove event that runs, and the reading of x,y will now be
wrong.

So that way i'll never get the Control.GetChildAtPoint to be anything else
but null. but if i'll in the forms mousemove event get the x,y and look at
x+1,y-1 ( or something like that ) i'll get the control when i'am almost
over the label.

Could you give me some more hints?

Kind regards
Johnny Jensen

>> Hello Group
>>
[quoted text clipped - 12 lines]
>
> Michael
Ben Voigt - 15 Nov 2006 22:22 GMT
> Hey Michael
>
[quoted text clipped - 13 lines]
>
> Could you give me some more hints?

You can do:

MouseMove += Form_MouseMove;
foreach (Control c in Controls)
   c.MouseMove += Form_MouseMove;

then in
void Form_MouseMove(object sender, MouseEventArgs e)
sender is the control beneath the mouse (you can surely cast it to Control),
and e will contain the relative coordinates to the upper left of sender.

> Kind regards
> Johnny Jensen
[quoted text clipped - 15 lines]
>>
>> Michael
Michael C - 19 Nov 2006 23:08 GMT
> So that way i'll never get the Control.GetChildAtPoint to be anything else
> but null. but if i'll in the forms mousemove event get the x,y and look at
> x+1,y-1 ( or something like that ) i'll get the control when i'am almost
> over the label.
>
> Could you give me some more hints?

In addition to what Ben said, you should add label1.x and label1.y to your x
and y values.

Michael

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.