Rizwan Ansari
Rizwan Ansari

Reputation: 439

Change language of a MonthCalender control

I am trying to change the language of a "monthcalender" control in windows form application. I have tried this:

System.Globalization.CultureInfo ci = 
    new System.Globalization.CultureInfo("fr-FR");

System.Threading.Thread.CurrentThread.CurrentCulture = ci;  

but it failed to change the language.

Upvotes: 2

Views: 4963

Answers (3)

Harsh Baid
Harsh Baid

Reputation: 7249

Yes it is possible but It seems there is no built-in support for c# programmes to supporting localization for MonthCalendar control as found on MSDN here which points to LOCALE_USER_DEFAULT to change the language.

But if you can find any way to change language in LOCALE_USER_DEFAULT from C++ application, to change in your application at runtime, as found from codeproject here and here which should result in changing culture for the MonthCalendar control.

I hope it helps you.

Update

I have found a VB.NET program for the purpose of changing LOCALE_USER_DEFAULT for which you have to enable unsafe programming and convert this to c# (I hope you don't mind if I don't convert vb to c#)

Reference MSDN Forum Link and one more here for arabic calendar

Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
Private Const LOCALE_USER_DEFAULT As Long = &H400
Private Const LOCALE_SSHORTDATE = &H1F

Private Function GetShortDateFormat() As String
Dim lngRet As Long
Dim strValue As String
Dim lngLength As Long
    lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strValue, lngLength)
    strValue = Space(lngRet)
    lngLength = lngRet
    lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strValue, lngLength)
    GetShortDateFormat = Left(strValue, lngLength - 1)
End Function

Private Function SetShortDateFormat(ByVal strFormat As String) As Boolean
Dim lngRet As Long
    lngRet = SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strFormat)
    SetShortDateFormat = CBool(lngRet)
End Function

Private Sub Command1_Click()
    MsgBox GetShortDateFormat
End Sub

Private Sub Command2_Click()
    If SetShortDateFormat(Text1.Text) Then
        MsgBox "Short Date Format Changed"
    Else
        MsgBox "Changing Short Date Format failed"
    End If
End Sub

Upvotes: 0

Damith
Damith

Reputation: 63065

MonthCalendar is a wrapper for the built-in Month Calendar control that does not support locales other than the user's default. You can try Culture Aware Month Calendar and DatePicker

Upvotes: 2

Habib
Habib

Reputation: 223207

You can't do that with MonthControl. You need to see: The DateTimePicker and MonthCalendar control do not reflect the CurrentUICulture property of an application's main execution thread when you created a localized application in the .NET Framework, in Visual Studio 2005, or in Visual Studio .NET

This behavior occurs because the DateTimePicker control and the MonthCalendar control are Microsoft Windows common controls. Therefore, the operating system's user locale determines the user interface of these controls.

Upvotes: 3

Related Questions