Click here to Skip to main content
11,493,233 members (58,715 online)
Click here to Skip to main content

Multi Culture Calendar

, 11 Sep 2009 CPOL 25.8K 1.2K 23
Rate this:
Please Sign up or sign in to vote.
A calendar which supports all types of calendars such as persian(Farsi)-Arabic and English calendars by changing the culture

Introduction

As you know, after changing the culture, all controls work with the new culture. In this control, you can use several calendars on a page and change the culture for each one.

The important thing is that Microsoft does not support the UI of the Persian calendar. Now you can use it very easily. It is possible to inherit this control from other controls which you want and make your custom controls.

Using the Code

The code is very easy and I override just the render method. Before the rendering and after that, I change the culture and only for Persian, I use Reflection to change the calendar (Shamsi Calendar).

Here is the important function on this control that shows you how it can be made possible using the Persian calendar:

private void ChangeCulture()
{
DefaultCulture = new System.Globalization.CultureInfo(
    System.Threading.Thread.CurrentThread.CurrentUICulture.Name);

switch (SelectedCulture.Name)
{
case "fa-IR":
System.Globalization.DateTimeFormatInfo info = SelectedCulture.DateTimeFormat;
info.AbbreviatedDayNames = new string[] { "ی", "§", "«", "چ", "پ", "¤", "¬" };
info.DayNames = new string[] { "یک¬ë ى", "§ي¬ë ى", "ﺳﻪ¬ë ى", "چىں©¬ë ى", "پ뤬ë ى",
    "¤êمى", "¬ë ى" };
info.AbbreviatedMonthNames = new string[] { "ه©ي©§یë", "ں©§ï ى¬¢", "¦©§ں§", "¢ï©",
    "ꩧں§", "¬ى©یي©", "êى©", "™ ںë", "™¨©", "§ی", " ىêë", "ں«هë§", "" };
info.MonthNames = new string[] 
    { "ه©ي©§یë", "ں©§ï ى¬¢", "¦©§ں§", "¢ï©", "ꩧں§", "¬ى©یي©", 
    "êى©", "™ ںë", "™¨©", "§ی", " ىêë", "ں«هë§", "" };
info.AMDesignator = "ç.â";
info.PMDesignator = " .â";
info.ShortDatePattern = "yyyy/MM/dd";
info.FirstDayOfWeek = DayOfWeek.Saturday;
System.Globalization.PersianCalendar cal = new System.Globalization.PersianCalendar();
typeof(System.Globalization.DateTimeFormatInfo).GetField(
    "calendar", System.Reflection.BindingFlags.Public |
    System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.NonPublic).SetValue(info, cal);

object obj = typeof(System.Globalization.DateTimeFormatInfo).GetField(
    "m_cultureTableRecord", System.Reflection.BindingFlags.Public |
    System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.NonPublic).GetValue(info);

obj.GetType().GetMethod("UseCurrentCalendar",
   System.Reflection.BindingFlags.NonPublic |
   System.Reflection.BindingFlags.Instance).Invoke(obj,
   new object[] { cal.GetType().GetProperty("ID",
   System.Reflection.BindingFlags.Instance |
   System.Reflection.BindingFlags.NonPublic).GetValue(cal, null) });

typeof(System.Globalization.CultureInfo).GetField("calendar",
    System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.NonPublic).SetValue(SelectedCulture, cal);

System.Threading.Thread.CurrentThread.CurrentCulture = SelectedCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = SelectedCulture;
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat = info;
System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat = info;
break;

default:
System.Threading.Thread.CurrentThread.CurrentCulture = SelectedCulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = SelectedCulture;
break;
}
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Farshid3003
Software Developer (Senior) Morhipo
Turkey Turkey
System Architect and software developer. Designing and developing infrastructures and frameworks using c#.net for win and web base solutions.
I have more than 10 years work experience in developing and designing.

Comments and Discussions

 
GeneralI don't know how it works! Pin
clickmeplz115-Apr-11 21:13
memberclickmeplz115-Apr-11 21:13 
GeneralRe: I don't know how it works! Pin
Farshid300316-Apr-11 23:57
memberFarshid300316-Apr-11 23:57 
Generalhi farshid3003 Pin
Alishafaat3-Sep-10 10:39
memberAlishafaat3-Sep-10 10:39 
GeneralRe: hi farshid3003 Pin
Farshid300317-Apr-11 0:00
memberFarshid300317-Apr-11 0:00 
GeneralCode access security Pin
arash.rohani25-Jun-10 6:08
memberarash.rohani25-Jun-10 6:08 
GeneralRe: Code access security Pin
Farshid300325-Jun-10 9:25
memberFarshid300325-Jun-10 9:25 
GeneralRe: Code access security Pin
arash.rohani25-Jun-10 10:48
memberarash.rohani25-Jun-10 10:48 
GeneralRe: Code access security Pin
Farshid300329-Jun-10 6:18
memberFarshid300329-Jun-10 6:18 
Generalit coulden't work with janus Pin
amin_ramin888610-Aug-08 6:15
memberamin_ramin888610-Aug-08 6:15 
GeneralRe: it coulden't work with janus Pin
Farshid300311-Sep-09 6:12
memberFarshid300311-Sep-09 6:12 
GeneralArticle seems incomplete Pin
Rob Graham26-Apr-08 12:05
memberRob Graham26-Apr-08 12:05 
GeneralRe: Article seems incomplete Pin
Farshid300311-Sep-09 6:16
memberFarshid300311-Sep-09 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 11 Sep 2009
Article Copyright 2008 by Farshid3003
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid