Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help extending the monthCalendar control.

Posted on 2008-06-25
11
Medium Priority
?
1,182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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