Solved

Help extending the monthCalendar control.

Posted on 2008-06-25
11
1,152 Views
Last Modified: 2013-11-26
I am wanting to extend the MonthCalendar control so that where it has the box/circle showing todays date at the bottom, I would like another itme below that showing the highlighted box and what it's date is(see picture).  I would like to add the line where the red arrow is....

I have gotten started with a little bit of code, but not sure exactly where to go from here. There are currently 2 properties that provide the visibility of the footer at the bottom, the ShowToday as Boolean and ShowTodayCircle as Boolean.

I would expect that on the Paint method it rights the date in the footer if the showTodat is set to true.  Is there a way to see the code for these items.  How do you know what to write for the OnPaint.

Thought this might be fun and challenging, but I have bitten off mor than I can chew I think.
Public Class myCalendar
    Inherits System.Windows.Forms.MonthCalendar
 
    Private _showDate As Boolean
    Public Property ShowDate() As Boolean
        Get
            Return _showDate
 
        End Get
        Set(ByVal value As Boolean)
 
            _showDate = value
        End Set
    End Property
 
    Private _showDateCircle As Boolean
    Public Property ShowDateCircle() As Boolean
        Get
            Return _showDateCircle
        End Get
        Set(ByVal value As Boolean)
 
            _showDateCircle = value
        End Set
       
    End Property

Open in new window

Image1.jpg
0
Comment
Question by:rgn2121
  • 8
  • 3
11 Comments
 
LVL 14

Expert Comment

by:rachitkohli
ID: 21863945
Hello,
I have written the code doing your functionality.
1. Make an windows user control project. Drop a Month calendar on it.
2. Exactly below it drop a label, with its AutoSize property as FALSE.
3. Now in the code window, paste the following code.
4. After pasting the code, build the project & use this control on any windows form, you will see it working the way you wanted with an additional item below showing the currently selected date & a blue rectangle next to it.
Hope it helps

    Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
        e.Graphics.FillRectangle(Brushes.Blue, 1, 1, 10, 10)
        e.Graphics.DrawString(MonthCalendar1.SelectionStart.ToLongDateString, New Font("Verdana", 7, FontStyle.Bold), Brushes.Black, 15, 0)
    End Sub
 
    Private Sub MonthCalendar1_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        Label1.Refresh()
    End Sub

Open in new window

calendar-ex.JPG
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21863999
That's great!!! Thanks...

Would I be able to make the Blue box appear the same shape and size as the Red outline box above it and also have the area where it is displayed as whitesmoke so it appears as though it is part of the control?
0
 
LVL 14

Accepted Solution

by:
rachitkohli earned 500 total points
ID: 21864085
Yes for that matter need to get the exact size of the red outline box.

Replace the paint event code with this & change the labels backcolor to white or whitesmoke, whichever you find good
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
        e.Graphics.FillRectangle(Brushes.Blue, 1, 1, 20, 12)
        e.Graphics.DrawString(MonthCalendar1.SelectionStart.ToLongDateString, New Font("Verdana", 7, FontStyle.Bold), Brushes.Black, 22, 0)
    End Sub

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 12

Author Comment

by:rgn2121
ID: 21868466
I will try it out later tonight and let you know...thanks
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21871623
Okay, the calendar works and displays as expected, but I don't have all of the properties that a normal calendar would have.  I assume this is because it inherits from UserControl and not MonthCalendar?

If I change it to monthCalendar though, I get errors about Auto size not being a member of MonthCalendar.  Anyway for me to have all of the properties of a normal calendar.  I have been able to create my own and they show up, surely I don't have to create all the ones that are missing do I?
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21871755
This is the code I have right now...I was trying to make the new properties I added show on the control when they are changed, but I am missing something.  Maybe I need to create a method to paint the label when they are updated?
Imports System.ComponentModel
Public Class MonthCalendarExt
 
 
    Private Sub labelCalendar_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles labelCalendar.Paint
        e.Graphics.FillRectangle(Brushes.Blue, 1, 1, 23, 14)
        e.Graphics.DrawString(_extraDate & MonthCalendar1.SelectionStart.ToShortDateString, New Font("Microsoft Sans Serif", 9, FontStyle.Bold), Brushes.Black, 24, 0)
    End Sub
 
    Private Sub MonthCalendar1_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateSelected
        labelCalendar.Refresh()
    End Sub
 
    Private _extraDate As String
    <Category("Behavior.ExtraDate"), _
        Description("Text diplayed as a description of the extra date."), _
        DefaultValue("NewDate")> _
    Public Property ExtraDate() As String
        Get
            Return _extraDate
        End Get
        Set(ByVal value As String)
            _extraDate = value
 
            Me.Invalidate()
        End Set
    End Property
 
    Private _showExtraDate As Boolean
    <Category("Behavior.ExtraDate"), _
        Description("Set to true to show the selected date under the Today's Date."), _
        DefaultValue(False)> _
    Public Property ShowExtraDate() As Boolean
        Get
            Return _showExtraDate
        End Get
        Set(ByVal value As Boolean)
            _showExtraDate = value
            Me.Invalidate()
        End Set
    End Property

Open in new window

0
 
LVL 14

Expert Comment

by:rachitkohli
ID: 21871863
On Paint Event write labelCalendar.Refresh()
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21871985
What about the Calendar properties...do I need to inherit from it instead...?
"Okay, the calendar works and displays as expected, but I don't have all of the properties that a normal calendar would have.  I assume this is because it inherits from UserControl and not MonthCalendar?

If I change it to monthCalendar though, I get errors about Auto size not being a member of MonthCalendar.  Anyway for me to have all of the properties of a normal calendar.  I have been able to create my own and they show up, surely I don't have to create all the ones that are missing do I?"
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21871999
when I added the labelCalendar.refresh() to the OnPaint, I no longer can see my properties in the property window.
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21889037
???
0
 
LVL 12

Author Comment

by:rgn2121
ID: 21919874
Any help with what I posted above?
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question