473,783 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Capture Month Change with MonthCalendar

I have a MonthCalendar on one of my forms. I have disovered that the
DateChanged event is triggered not only when the user clicks on a new
date, but also if they click on the Previous or Next Month arrows
(meaning they click on either of the left or right pointing arrows in
the top corner). If the user changes the month, it messes up some of
the date logic that I have in the DateChanged event. Does anybody
know how I can capture this action? I'd like my code in the
DateChanged routine to work like this:

If MonthNotChanged then
Do Something
Else 'month changed
Do something Else
End if

Thanks,
Randy

Oct 7 '07 #1
11 7390
Randy,

Did you try the other events, I use always the TextChanged one?

Cor
Oct 7 '07 #2
I don't see TextChanged in the list of events. I looked at the other
events, but I don't see anything that is more appropriate.

Oct 7 '07 #3

http://msdn2.microsoft.com/en-us/lib...xtchanged.aspx
>I don't see TextChanged in the list of events. I looked at the other
events, but I don't see anything that is more appropriate.
Oct 8 '07 #4
Charlie,
I was going down the same path with using an If statement to check if
the month had changed. Unfortunately, this doesn't always work. If
you look at the calendar view, you can often see the last few days of
the previous month or the first few days of the succeeding month. If
the user were to click on these dates, the logic you propose would
conclude that the user had clicked the arrow, not the date. I'll post
my code below for anybody who is interested.

What I am trying to do is execute certain lines of code *only* if the
user has selected a date. If they are clicking on one of the arrows,
I am treating this action as the user *navigating* to a date (as
opposed to actually selecting one). So if they were to click Sep 28
while viewing the Oct calendar, this would qualify as *selecting* a
date, and thus would initiate a sequence of actions. If they clicked
the left arrow, this is simply a navigational move and would be
disregarded. I've looked for patterns in how the MonthCalendar
handles these arrow clicks, but I'm not seeing reliable patterns that
I can code around.

Somehow, the control must distinguish these arrows or it wouldn't work
as it does. So the question is still, how can I trap these clicks in
my VB code? If I can figure that out, it will make my programming
monumentally easier as well as more reliable.
Private Sub MonthCalendar1_ DateChanged(ByV al sender As Object, ByVal e
As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
'If there are unsaved changes, alert the user
If bLoading = False Then
If bUnsaved = True Then
frmDateChange.S how()
Exit Sub
End If

'This is where I'm stuck trying to trap the arrow click
Dim d As Date = e.Start
'Me.Text = Me.CurrentSelec tedDate
If d.AddMonths(-1).Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Right arrow clicked."
Call SelectDates()
End If
ElseIf d.AddMonths(1). Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Left arrow clicked."
Call SelectDates()
End If
Else
Me.Text = d.ToString & " Date changed."
Call SelectDates()
Call RemoveControls( )
Call AddDataRows()
End If
Me.CurrentSelec tedDate = d
End If
End Sub

Private Sub SelectDates()
Dim i As Integer =
CInt(MonthCalen dar1.SelectionS tart.DayOfWeek)
Dim d As Date = MonthCalendar1. SelectionStart
Dim a As Integer
If i = 0 Then
a = -6
Else
a = 1 - i
End If
MonthCalendar1. SelectionStart = d.AddDays(a)

If i = 0 Then
a = 0
Else
a = 7 - i
End If
MonthCalendar1. SelectionEnd = d.AddDays(a)
End Sub

So, how do I trap this arrow click? Or if there is no way, how can I
program the logic to identify and trap the conditions that would would
be present if the arrows are clicked? Any help is appreciated.

Thanks,
Randy

Oct 9 '07 #5
You could add another event handler to the code I previously provided...In
fact, this would probably do it on its own...

The MonthCalendar.M ouseDown event (e as MouseEventArgs) captures the X and Y
coordinates relative to the control itself...My test shows that Y < 24 for a
click of the month buttons...

"Randy" wrote:
Charlie,
I was going down the same path with using an If statement to check if
the month had changed. Unfortunately, this doesn't always work. If
you look at the calendar view, you can often see the last few days of
the previous month or the first few days of the succeeding month. If
the user were to click on these dates, the logic you propose would
conclude that the user had clicked the arrow, not the date. I'll post
my code below for anybody who is interested.

What I am trying to do is execute certain lines of code *only* if the
user has selected a date. If they are clicking on one of the arrows,
I am treating this action as the user *navigating* to a date (as
opposed to actually selecting one). So if they were to click Sep 28
while viewing the Oct calendar, this would qualify as *selecting* a
date, and thus would initiate a sequence of actions. If they clicked
the left arrow, this is simply a navigational move and would be
disregarded. I've looked for patterns in how the MonthCalendar
handles these arrow clicks, but I'm not seeing reliable patterns that
I can code around.

Somehow, the control must distinguish these arrows or it wouldn't work
as it does. So the question is still, how can I trap these clicks in
my VB code? If I can figure that out, it will make my programming
monumentally easier as well as more reliable.
Private Sub MonthCalendar1_ DateChanged(ByV al sender As Object, ByVal e
As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
'If there are unsaved changes, alert the user
If bLoading = False Then
If bUnsaved = True Then
frmDateChange.S how()
Exit Sub
End If

'This is where I'm stuck trying to trap the arrow click
Dim d As Date = e.Start
'Me.Text = Me.CurrentSelec tedDate
If d.AddMonths(-1).Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Right arrow clicked."
Call SelectDates()
End If
ElseIf d.AddMonths(1). Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Left arrow clicked."
Call SelectDates()
End If
Else
Me.Text = d.ToString & " Date changed."
Call SelectDates()
Call RemoveControls( )
Call AddDataRows()
End If
Me.CurrentSelec tedDate = d
End If
End Sub

Private Sub SelectDates()
Dim i As Integer =
CInt(MonthCalen dar1.SelectionS tart.DayOfWeek)
Dim d As Date = MonthCalendar1. SelectionStart
Dim a As Integer
If i = 0 Then
a = -6
Else
a = 1 - i
End If
MonthCalendar1. SelectionStart = d.AddDays(a)

If i = 0 Then
a = 0
Else
a = 7 - i
End If
MonthCalendar1. SelectionEnd = d.AddDays(a)
End Sub

So, how do I trap this arrow click? Or if there is no way, how can I
program the logic to identify and trap the conditions that would would
be present if the arrows are clicked? Any help is appreciated.

Thanks,
Randy

Oct 9 '07 #6
The mousedown event happens AFTER the datechanged event, so you may have to
capture any needed parameters in the datechanged event, and let the mousedown
event act on those parameters after determining where the user clicked...

As I was writing the previous note, I assumed the events processed in
reverse to how they actually process...Oh well, it really should not be much
of a problem.

"Randy" wrote:
Charlie,
I was going down the same path with using an If statement to check if
the month had changed. Unfortunately, this doesn't always work. If
you look at the calendar view, you can often see the last few days of
the previous month or the first few days of the succeeding month. If
the user were to click on these dates, the logic you propose would
conclude that the user had clicked the arrow, not the date. I'll post
my code below for anybody who is interested.

What I am trying to do is execute certain lines of code *only* if the
user has selected a date. If they are clicking on one of the arrows,
I am treating this action as the user *navigating* to a date (as
opposed to actually selecting one). So if they were to click Sep 28
while viewing the Oct calendar, this would qualify as *selecting* a
date, and thus would initiate a sequence of actions. If they clicked
the left arrow, this is simply a navigational move and would be
disregarded. I've looked for patterns in how the MonthCalendar
handles these arrow clicks, but I'm not seeing reliable patterns that
I can code around.

Somehow, the control must distinguish these arrows or it wouldn't work
as it does. So the question is still, how can I trap these clicks in
my VB code? If I can figure that out, it will make my programming
monumentally easier as well as more reliable.
Private Sub MonthCalendar1_ DateChanged(ByV al sender As Object, ByVal e
As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
'If there are unsaved changes, alert the user
If bLoading = False Then
If bUnsaved = True Then
frmDateChange.S how()
Exit Sub
End If

'This is where I'm stuck trying to trap the arrow click
Dim d As Date = e.Start
'Me.Text = Me.CurrentSelec tedDate
If d.AddMonths(-1).Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Right arrow clicked."
Call SelectDates()
End If
ElseIf d.AddMonths(1). Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Left arrow clicked."
Call SelectDates()
End If
Else
Me.Text = d.ToString & " Date changed."
Call SelectDates()
Call RemoveControls( )
Call AddDataRows()
End If
Me.CurrentSelec tedDate = d
End If
End Sub

Private Sub SelectDates()
Dim i As Integer =
CInt(MonthCalen dar1.SelectionS tart.DayOfWeek)
Dim d As Date = MonthCalendar1. SelectionStart
Dim a As Integer
If i = 0 Then
a = -6
Else
a = 1 - i
End If
MonthCalendar1. SelectionStart = d.AddDays(a)

If i = 0 Then
a = 0
Else
a = 7 - i
End If
MonthCalendar1. SelectionEnd = d.AddDays(a)
End Sub

So, how do I trap this arrow click? Or if there is no way, how can I
program the logic to identify and trap the conditions that would would
be present if the arrows are clicked? Any help is appreciated.

Thanks,
Randy

Oct 9 '07 #7
And just in case you're not always depending on a mouse click for a date
change, you could use a timer to postpone the code of the datechanged event
(maybe 100 ms?, to see if the mouseclick occurred.

"Randy" wrote:
Charlie,
I was going down the same path with using an If statement to check if
the month had changed. Unfortunately, this doesn't always work. If
you look at the calendar view, you can often see the last few days of
the previous month or the first few days of the succeeding month. If
the user were to click on these dates, the logic you propose would
conclude that the user had clicked the arrow, not the date. I'll post
my code below for anybody who is interested.

What I am trying to do is execute certain lines of code *only* if the
user has selected a date. If they are clicking on one of the arrows,
I am treating this action as the user *navigating* to a date (as
opposed to actually selecting one). So if they were to click Sep 28
while viewing the Oct calendar, this would qualify as *selecting* a
date, and thus would initiate a sequence of actions. If they clicked
the left arrow, this is simply a navigational move and would be
disregarded. I've looked for patterns in how the MonthCalendar
handles these arrow clicks, but I'm not seeing reliable patterns that
I can code around.

Somehow, the control must distinguish these arrows or it wouldn't work
as it does. So the question is still, how can I trap these clicks in
my VB code? If I can figure that out, it will make my programming
monumentally easier as well as more reliable.
Private Sub MonthCalendar1_ DateChanged(ByV al sender As Object, ByVal e
As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
'If there are unsaved changes, alert the user
If bLoading = False Then
If bUnsaved = True Then
frmDateChange.S how()
Exit Sub
End If

'This is where I'm stuck trying to trap the arrow click
Dim d As Date = e.Start
'Me.Text = Me.CurrentSelec tedDate
If d.AddMonths(-1).Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Right arrow clicked."
Call SelectDates()
End If
ElseIf d.AddMonths(1). Month = Me.CurrentSelec tedDate.Month
Then
If d.Day = 1 Then
Me.Text = d.ToString & " Left arrow clicked."
Call SelectDates()
End If
Else
Me.Text = d.ToString & " Date changed."
Call SelectDates()
Call RemoveControls( )
Call AddDataRows()
End If
Me.CurrentSelec tedDate = d
End If
End Sub

Private Sub SelectDates()
Dim i As Integer =
CInt(MonthCalen dar1.SelectionS tart.DayOfWeek)
Dim d As Date = MonthCalendar1. SelectionStart
Dim a As Integer
If i = 0 Then
a = -6
Else
a = 1 - i
End If
MonthCalendar1. SelectionStart = d.AddDays(a)

If i = 0 Then
a = 0
Else
a = 7 - i
End If
MonthCalendar1. SelectionEnd = d.AddDays(a)
End Sub

So, how do I trap this arrow click? Or if there is no way, how can I
program the logic to identify and trap the conditions that would would
be present if the arrows are clicked? Any help is appreciated.

Thanks,
Randy

Oct 9 '07 #8
Thanks a lot, Charlie. These are great suggestions. I'm having a
little trouble implementing it, however, as I cannot get predictable
values for the coordinates where the arrows would have to exist.
Since this is a separate topic from just determining if the arrow has
been clicked, I started a new post. (search: Find Mouse Coordinates
Within Control). I'd appreciate if you have any ideas.

Thanks again for all of your help. I really appreciate it.
Randy

Oct 11 '07 #9
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
Oct 14 '07 #10

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

Similar topics

20
5047
by: Laguna | last post by:
Hi Gurus, I want to find the expiration date of stock options (3rd Friday of the month) for an any give month and year. I have tried a few tricks with the functions provided by the built-in module time, but the problem was that the 9 element tuple need to be populated correctly. Can anyone help me out on this one? Thanks a bunch, Laguna
0
1063
by: David | last post by:
Hi, I have a MainForm with a Subform. On the Mainform are 3 Textboxes: Order Qty, Qty Shipped & Qty Outstanding Order Qty is a set figure for display purposes only Qty Shipped is a textbox which just runs a calculation which sums a field in each record on the Subform.
2
1372
by: MAX SMITH | last post by:
I'm a newbie to Access and am having trouble understanding the logic behind queries. I have 2 tables, 1 for stock in and 1 for stock out. I have joined these in a union query. the fields I have are: Month Stockpile Stock type1 Stock type2 Stock type3 Stock type4
10
3898
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing something in the module or the code in Stephan's MonthCalendar? Thanks, TySmith -- Message posted via http://www.accessmonster.com
6
10817
by: Carlos García-Carazo | last post by:
Hello, I am working on a C# application for an industrial machine, using Windows Forms, where the user could look at the screen from a 90 degree rotated position, like he could turn the monitor to leave it standing on its left (or right) side. There are many ways to show a "turned" interface in this case, but the problem is that when he moves the mouse right, in a turned screen the mouse cursor goes down (or up), when he moves it up...
3
11009
by: RG | last post by:
For a Windows project in VB.NET 2003: I need a Calendar that’s much larger than the MonthCalendar control in the toolbox; it needs to fill the whole screen (at least approximately ). VB won’t allow me to change the Size Height or Width Properties. I see that you can size a Calendar control in a Web project all you like; but I’m creating a Windows application project here. I see that Size comes from System.Drawing.Size...
1
3531
by: DS | last post by:
I seem to have run into another strange anomaly with the monthCalendar control. I want to display 6 months at time with either the first half of the year (January-June) or the later half of the year (July-Dec) being rendered- depending on where todays date falls. I also want today's date to be selected. This poses a problem. Refer to the code below. Add a call to createCalendar() to your constructor (AFTER the InitializeComponents()...
3
2541
by: gv | last post by:
Hi all, Using VB Express 2005 How do I get the day of the first day of the month using the MonthCalendar control. so if the MonthCalendar control is set to the systems date. thanks
1
2415
by: Gidi | last post by:
Hi, I'm using 3 months calendars control. I set one of them to show the current month (october), and I want the second and third to show one and two month forward. How can it be done?
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.