locked
VS2015 using VB - Month Calendar RRS feed

  • Question

  • I can not make the Month Calendar larger or change colors in the Month Calendar.  The size parameter does not change the size and changing the Background and forecolor does not change.

    Edcal

    Wednesday, December 6, 2017 2:44 PM

Answers

  • You must disable Visual Styles for the control to change colors (with SetWindowTheme() for example):

    <DllImport("Uxtheme.dll", SetLastError:=True)>
    Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer    
    End Function

    Wednesday, December 6, 2017 3:53 PM

All replies

  • You must disable Visual Styles for the control to change colors (with SetWindowTheme() for example):

    <DllImport("Uxtheme.dll", SetLastError:=True)>
    Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Integer    
    End Function

    Wednesday, December 6, 2017 3:53 PM
  • I don't think you can resize it.

    Wednesday, December 6, 2017 3:53 PM
  • Set Max and Min sizes, that will get you started.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, December 6, 2017 4:06 PM
  •  If you have not changed the MaximumSize from the default of (0,0),  then you can resize it in the designer window.  Just be aware that it's size will snap the size to fit 1 month more after you have resized it enough.  For example, notice how jumps to the next size that fits another full month...

     

      You can also set the CalendarDimensions property to set the columns/rows of months to display in the designer window.  If doing it in code then use the SetCalendarDimensions method to set it as shown in the example below.  As far as changing the colors and the Font size,  you will need to disable the control from using visual styles as Castorix31 mentioned.  That is also shown in the example below.

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("uxtheme.dll")>
        Private Shared Function SetWindowTheme(ByVal hwnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszSubAppName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszSubIdList As String) As Integer
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            SetWindowTheme(MonthCalendar1.Handle, "", "") 'disable the visual style for the MonthCalandar control
            MonthCalendar1.SetCalendarDimensions(3, 2) 'display 3 months horizontally and 2 months vertically
            MonthCalendar1.ScrollChange = 3 'scroll 3 months at a time when the user clicks the left or right scroll arrows
            MonthCalendar1.BackColor = Color.Blue
            MonthCalendar1.ForeColor = Color.White
            MonthCalendar1.TitleBackColor = Color.WhiteSmoke
            MonthCalendar1.TitleForeColor = Color.Black
            MonthCalendar1.TrailingForeColor = Color.Red
            MonthCalendar1.Font = New Font(MonthCalendar1.Font.FontFamily, 10, FontStyle.Bold) 'make the font bigger to make each month of the calendar bigger.
        End Sub
    End Class
     

     Here is what the above example looks...

     If you want just one month shown and just want the month to be larger,  then you can just disable it from using visual styles and set it's font larger....

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("uxtheme.dll")>
        Private Shared Function SetWindowTheme(ByVal hwnd As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszSubAppName As String, <MarshalAs(UnmanagedType.LPWStr)> ByVal pszSubIdList As String) As Integer
        End Function
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            SetWindowTheme(MonthCalendar1.Handle, "", "") 'disable the visual style for the MonthCalandar control
            MonthCalendar1.BackColor = Color.Blue
            MonthCalendar1.ForeColor = Color.White
            MonthCalendar1.TitleBackColor = Color.WhiteSmoke
            MonthCalendar1.TitleForeColor = Color.Black
            MonthCalendar1.TrailingForeColor = Color.Red
            MonthCalendar1.Font = New Font(MonthCalendar1.Font.FontFamily, 24, FontStyle.Bold) 'make the font bigger to make each month of the calendar bigger.
        End Sub
    End Class
     

     That example looks like this...


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Wednesday, December 6, 2017 7:51 PM
    • Proposed as answer by Mr. Monkeyboy Wednesday, December 6, 2017 7:52 PM
    Wednesday, December 6, 2017 7:47 PM