473,586 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find Mouse Coordinates Within Control

I'm struggling with identifying whether a user has clicked on the left
or right arrows within the MonthCalendar controls. I had a good
suggestion to trap the mouse coordinates that the user clicks to
determine if they have clicked within the region where the arrow
exists. My problem is that my form is not maximized and therefore the
control can exist almost anywhere on the user's screen. I thought
about forcing the form to a fixed position, but I'd rather not do this
unless I have to.

What I thought might work would be to calculate the coordinate that
the user clicked relative to the position of the form since the
control is always in the same place relative to the form itself. Here
is the code that I am working on (excerpted):

Private Sub MonthCalendar1_ DateChanged(ByV al sender As Object, ByVal e
As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
Dim x As Integer = Val(System.Wind ows.Forms.Curso r.Position.X) -
Val(Me.MonthCal endar1.Location .X)
Dim y As Integer = Val(System.Wind ows.Forms.Curso r.Position.Y) -
Val(Me.MonthCal endar1.Location .Y)
Dim d As Date = e.Start
If x < ????? Then
If y < ????? Then
Me.Text = x & ", " & y & " Left arrow clicked"
End If
End If
End Sub
I thought that this would work, but I'm not getting predictable values
of x and y. Can anybody help me figure out how to do this?

Thanks,
Randy

Oct 11 '07 #1
1 4754
Annie,

I replied to one of Randy's 10/14 messages (in the thread that he started on
10/6) with some code I wrote and tested.
"Annie McCall" wrote:
I answered same on your other thread on MonthCalendar.
View Message Thread (11 replies)

+ Previous Page Results 11 - 12 of 12

Capture Month Change with MonthCalendar
From: Unknown User
Date Posted: 10/14/2007 8:42:00 AM

Hi Randy,

I am having the same problem. I need to know whether they clicked on the
arrow to change the month or actually selected a date.

I have you had any luck solving this? Can you post your solution?

In the meantime, I will continue researching for some solution. I will
post if I have any success.

This seems so basic. I'm sure we'll find a solution.

Thanks,
Annie

EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com

Re: Capture Month Change with MonthCalendar
From: Annie McCall
Date Posted: 10/14/2007 10:26:00 AM

Hi Randy,
I found a solution that works very well for me.

private void monthCalendarDa te_MouseDown(ob ject sender,
System.Windows. Forms.MouseEven tArgs e) {

MonthCalendar.H itTestInfo oHTI = monthCalendarDa te.HitTest(e.X, e.Y);

if ( oHTI.HitArea == MonthCalendar.H itArea.PrevMont hButton){
MessageBox.Show ("Left arrow hit");
return;
}

if ( oHTI.HitArea == MonthCalendar.H itArea.NextMont hButton)
{
MessageBox.Show ("Right arrow hit");

return;

}

if ( oHTI.HitArea == MonthCalendar.H itArea.Date ||
oHTI.HitArea == MonthCalendar.H itArea.PrevMont hDate
||
oHTI.HitArea ==
MonthCalendar.H itArea.NextMont hDate){
this.txtJobDate .Text =
this.dateValue_ Renamed; this.monthCalen darDate.Visible = false;

}
}
You can detect in MouseDown event using the hitarea. In my case I only
wanted to set the visible property of my monthcalendar to false if they
actually entered a date.

dateValue_Renam ed is a global variable I set in the datechange event.

Hope this helps you.


Annie McCall

*** Sent via Developersdex http://www.developersdex.com ***
Oct 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4475
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this: HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as...
5
1495
by: Smoke | last post by:
What i want to do, is, in the Activate Event of my form, determine which is the mouse possition, or, maybe even easy, just determine if the mouse is over my form. I need to do two differents things on that event, based on if the mouse is over the form or not.. Any help? Thanks.
8
2773
by: Tom | last post by:
Hi I am having problems working out if the mouse pointer is within the control bounds within the OnMouseMove method: Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs) Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y)) End Sub
13
3135
by: Lars Netzel | last post by:
Hi! I have a round area which I want to be able to move the mouse over and fire off events... how do I do that? I have drawn a FillPie Graphics and I feel that there has to be a way of getting to know if the mouse is over that area since I have the coordinates to paint the Pie but I don't know where to start or what to look for really. ...
3
63339
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the...
7
3632
by: RobKinney1 | last post by:
The subject line sounds a little funny, let me quickly explain: I have created a custom control using ComboBox. But inside my class, I need to know when the user does NOT click my control. Of course, I can capture the event Click when someone clicks on the actual control, but not when they click off of it. Right now I am using the...
2
19579
by: quickcur | last post by:
Hi, I have html like this: <div id="myCanvas" style="border:10px, black;position:relative;height:250px;width:100%;"> <img id="p" src="p.jpg"> </div> When user click the mosue, I would like 1. Test if the mouse location is on top of the image
4
2890
by: =?Utf-8?B?Unlhbg==?= | last post by:
I have a winform containing a scrollable panel and a groupbox inside the panel. There is a button inside the groupbox. When that button is clicked; how do I capture and display the X and Y coordinates in a messagebox?
4
3495
by: mbatestblrock | last post by:
I hope this makes some sense. My ultimate goal here is to execute a block of code if the mouse has not moved in a minute or so within the broswer. The machine I am running this on is for internal use only, so I have no fear of this not working in certain browsers, etc. I am no javascript pro but know enough to catch on if anyone is kind...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.