473,795 Members | 3,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Highlight entire week in MonthCalendar Control

Based on the date that the user selects, I'm trying to make the
MonthCalendar control highlight the entire week. In my case, the week
is from Monday - Sunday. I thought that using AddBoldedDate along
with selectionrange. start and .end would accomplish this, but it
doesn't.

Here is my code:

Private Sub MonthCalendar1_ DateChanged(ByV al sender As System.Object,
ByVal e As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
Dim dateToday As Date = MonthCalendar1. SelectionRange. Start
Dim LastMonday As Date
Select Case dateToday.DayOf Week
Case DayOfWeek.Monda y
LastMonday = MonthCalendar1. SelectionRange. Start
Case DayOfWeek.Tuesd ay
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-1)
Case DayOfWeek.Wedne sday
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-2)
Case DayOfWeek.Thurs day
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-3)
Case DayOfWeek.Frida y
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-4)
Case DayOfWeek.Satur day
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-5)
Case DayOfWeek.Sunda y
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-6)
End Select

With MonthCalendar1
.SelectionRange .Start = LastMonday
.SelectionRange .End = LastMonday.AddD ays(7)
for x = 0 to 6
.AddBoldedDate( LastMonday.AddD ays(x))
next
End With
End Sub

Thanks,
Randy

Sep 24 '07 #1
5 8733
Any takers?

Sep 24 '07 #2
I was looking to solve the same problem when I found your post. This
works for me:

Private Sub dtPick1_DateSel ected(ByVal sender As System.Object,
ByVal e As System.Windows. Forms.DateRange EventArgs) Handles
dtPick1.DateSel ected
Dim i As Integer = CInt(dtPick1.Se lectionStart.Da yOfWeek)
Dim d As Date = dtPick1.Selecti onStart
dtPick1.Selecti onStart = d.AddDays(1 - i)
dtPick1.Selecti onEnd = d.AddDays(7 - i)
End Sub

Note that I'm triggering off the DateSelected event, not DateChanged,
that way it doesn't re-trigger itself.
The seed values in the AddDays method make it Monday first day of
week. Otherewise use 0 and 6.
Enums always have an integer value behind, so you can avoid the Select
Case language.

Bob Graham

On Sep 23, 5:44 pm, Randy <spam.eastl...@ gmail.comwrote:
Based on the date that the user selects, I'm trying to make the
MonthCalendar control highlight the entireweek. In my case, theweek
is from Monday - Sunday. I thought that using AddBoldedDate along
with selectionrange. start and .end would accomplish this, but it
doesn't.

Here is my code:

Private Sub MonthCalendar1_ DateChanged(ByV al sender As System.Object,
ByVal e As System.Windows. Forms.DateRange EventArgs) Handles
MonthCalendar1. DateChanged
Dim dateToday As Date = MonthCalendar1. SelectionRange. Start
Dim LastMonday As Date
SelectCase dateToday.DayOf Week
Case DayOfWeek.Monda y
LastMonday = MonthCalendar1. SelectionRange. Start
Case DayOfWeek.Tuesd ay
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-1)
Case DayOfWeek.Wedne sday
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-2)
Case DayOfWeek.Thurs day
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-3)
Case DayOfWeek.Frida y
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-4)
Case DayOfWeek.Satur day
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-5)
Case DayOfWeek.Sunda y
LastMonday =
MonthCalendar1. SelectionRange. Start.AddDays(-6)
EndSelect

With MonthCalendar1
.SelectionRange .Start = LastMonday
.SelectionRange .End = LastMonday.AddD ays(7)
for x = 0 to 6
.AddBoldedDate( LastMonday.AddD ays(x))
next
End With
End Sub

Thanks,
Randy

Sep 25 '07 #3
Actually I've found a flaw in the case where a user selects a sunday,
it goes to the next week, but that should be easy to fix with an IIF
or whatever.

Sayonnara, Bob

Sep 25 '07 #4
Another flaw!!! Works pretty well in Vista but causes some display
corruption in XP...
Sep 25 '07 #5
That works perfectly.

For anybody who happens upon this post, the major difference (besides
that Bob's code is much more efficient) seems to be that I was using
selectionrange. start (and end) where Bob is using selectionstart and
selectionend.

Thanks, Bob!
Randy

Sep 27 '07 #6

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

Similar topics

20
5049
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
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
3
14263
by: michael_hk | last post by:
Hi, I am new to Windows Form programming and now have a simple Q about MonthCalendar. I want to hightlight some days in the calendar by changing the background color of these days. But I can't find any property or method that let me do this. What I know is that I can bold them... Thanks.
0
1271
by: Patrick Bustraen | last post by:
I would like to paint a transparent color bar on a weekrow in the MonthCalender Control. This would make it possible to select a week. In Outlook 2003 the control is used in such a way, but for me - using the dotnet forms - it seems impossible. The MonthCalender Control does not expose the Paint event or such... the only way I see up to now is to paint myself the whole control... but I hope there is a way to arrange this with much lesser...
2
5119
by: Robert Misiak | last post by:
Hi everyone- I've done a lot of searching around on the web and I'm sure the answer to this question is no, but I'll ask anyway. Is it possible to create an inherited MonthCalendar control and override the member that paints the background? I've tried working with OnPaint, OnPaintBackground to no avail. Perhaps someone has a similar calendar control implementation out there? Thanks, Robert
8
2620
by: vbmark | last post by:
I want the MonthCalendar control to return the single day selected. I have MaxSelectionCount = 1. What I get back though is this: "SelectionRange: Start: 5/5/2005 12:00:00 AM, End: 5/5/2005 12:00:00 AM" How do I get the single day date?
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()...
2
5537
by: meska | last post by:
Hi all, Scenario: I have a MonthCalendar control, and DataGridView. Depending on dates displayed in MonthCalendar I want to update information from database. The Possible Solution: So I must use DateChanged and/or DateSelected events to get the new dates
0
9672
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
9519
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
10213
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...
1
10163
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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
7538
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
6779
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
5436
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2920
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.