Solved

Help extending the monthCalendar control.

Posted on 2008-06-25
11
1,149 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 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