By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

Find Mouse Coordinates Within Control

P: n/a
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
MonthCalendar1.DateChanged
Dim x As Integer = Val(System.Windows.Forms.Cursor.Position.X) -
Val(Me.MonthCalendar1.Location.X)
Dim y As Integer = Val(System.Windows.Forms.Cursor.Position.Y) -
Val(Me.MonthCalendar1.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
Share this Question
Share on Google+
1 Reply


P: n/a
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 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");
return;
}

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

return;

}

if ( oHTI.HitArea == MonthCalendar.HitArea.Date ||
oHTI.HitArea == MonthCalendar.HitArea.PrevMonthDate
||
oHTI.HitArea ==
MonthCalendar.HitArea.NextMonthDate){
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.