471,853 Members | 824 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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(ByVal sender As Object, ByVal e
As System.Windows.Forms.DateRangeEventArgs) Handles
Dim x As Integer = Val(System.Windows.Forms.Cursor.Position.X) -
Dim y As Integer = Val(System.Windows.Forms.Cursor.Position.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?


Oct 11 '07 #1
1 4687

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.


EggHeadCafe - .NET Developer Portal of Choice

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 monthCalendarDate_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {

MonthCalendar.HitTestInfo oHTI = monthCalendarDate.HitTest(e.X,e.Y);

if ( oHTI.HitArea == MonthCalendar.HitArea.PrevMonthButton){
MessageBox.Show("Left arrow hit");

if ( oHTI.HitArea == MonthCalendar.HitArea.NextMonthButton)
MessageBox.Show("Right arrow hit");



if ( oHTI.HitArea == MonthCalendar.HitArea.Date ||
oHTI.HitArea == MonthCalendar.HitArea.PrevMonthDate
oHTI.HitArea ==
this.txtJobDate.Text =
this.dateValue_Renamed; this.monthCalendarDate.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_Renamed 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rick Strahl [MVP] | last post: by
5 posts views Thread by Smoke | last post: by
8 posts views Thread by Tom | last post: by
13 posts views Thread by Lars Netzel | last post: by
7 posts views Thread by RobKinney1 | last post: by
2 posts views Thread by quickcur | last post: by
4 posts views Thread by =?Utf-8?B?Unlhbg==?= | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

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.