First of all a summery for those who have the same problem but cant find the solution on the internet :
vb.net MonthCalendar1 visualstyles xp Theme displayMode windows 7
The thing I was trying to accomplish was the following :
A . Get a monthCalendar soutible for a touchscreen
B. with visualstyles in win7 /xp themeing ON
C. Start the calendar in the Year modus, without the controle SDK, so that you can select the year / month/ day within 3 clicks, instead of 3 clicks to zoom out and then 3 clicks to zoom in.
The thing is that the MonthCalendar will display 3 or more months if you stretch it out (600 by 600), if you change the font to size 32 and visualstyles is turned OFF it will display correctly.
but if it's turned ON you just see 3 months with verry small dates, you can understand that that isn't soutible for a touchscreen. As we are in 2010 and everybody has visual styles ON
and the view off
vb in win95 was ok in 1995, it is awfull now.
Lot of searching on Hinder-net and lots of trial on error
But with a bit of effort it finally succeded.
Here's the code for it (No Imports/ useing needed)
From the calling form :
Code:
Dim frmToshow As frmCalendar
frmToshow = New frmCalendar
frmToshow.initialize()
frmToshow.Show()
Here is the code that displays the calendar
Code:
Public Class ofrmCalendar
Friend Declare Unicode Function SetWindowTheme Lib "UxTheme.dll" _
(ByVal hwnd As IntPtr, _
ByVal pszSubAppName As String, _
ByVal pszSubIdList As String) As Integer
'Not useing this but if you need it here it is.
Private Sub EnableVisualStyles(ByVal control As Control)
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
SetWindowTheme(control.Handle, Nothing, Nothing)
End If
End Sub
Private Sub DisableVisualStyles(ByVal control As Control)
If OSFeature.Feature.IsPresent(OSFeature.Themes) Then
SetWindowTheme(control.Handle, "", "")
End If
End Sub
Friend Sub initialize()
DisableVisualStyles(Me.MonthCalendar1)
MonthCalendar1.MinDate = Now.AddYears(-1) ' can go 1 year back to select a date
End Sub
Private Sub calendar_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MonthCalendar1.Focus()
' ctrl + arrow key up will zoom out once to display the month of that year
' so this simmulates a click on the controle to zoom out,
' do it twice and you have the decade view (three times and your in year range modus)
SendKeys.Send("^({UP})")
SendKeys.Send("^({UP})")
End Sub
End Class
success