Solved

Help extending the monthCalendar control.

Posted on 2008-06-25
11
1,139 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now