To be frank, no.
I find VB very confusing and avoid using it.
I would not like to invest the time needed to insure proper wiriting of VB
code
Should someone who understands VB better than me do the basic work of
translating the relativly small portion of code needed, I wold test and
update the results to my homepage.
I hope microsoft release a proper version in the next CF.
Yes, I agree.
90% of my code are inside 2 Language Properties that I have added to the
Original code.
2 Methods have minimal changes, basicly using strings set in the Language
Properties instead of const Strings.
CalculateFirstDate() has been compleatly changed to support FirstDayof Week
logic.
Otherwise no changes were made to the Original code.
Here is the compleate code where changes have been made/included in C#
public class DateTimePicker : Control
{
public DateTimePicker()
{ // mj10777 Language Support
m_dayPicker = new DayPickerPopup(ip_Language);
// hookup day picker events
m_dayPicker.CloseUp += new EventHandler(OnDayPickerCloseUp);
m_dayPicker.ValueChanged += new EventHandler(OnDayPickerValueChanged);
} // public DateTimePicker()
// mj10777 Language Support
private int ip_Language = 1; // English
/// <summary>
/// mj10777 Language Support
/// - I am using the Telefon Codes for the Languages
/// - unsupported languages are defaulted to English
/// - Date Formatting is Maschine specific
/// - I hope that all formats are supported
/// </summary>
public int Language
{
get
{
return ip_Language;
}
set
{
ip_Language = value; // Supported Languages checked in DayPickerPopup
m_dayPicker = new DayPickerPopup(ip_Language);
// hookup day picker events
m_dayPicker.CloseUp += new EventHandler(OnDayPickerCloseUp);
m_dayPicker.ValueChanged += new EventHandler(OnDayPickerValueChanged);
}
}
}
class DayPickerPopup : Control
{
#region mj10777 Language Support
// mj10777 Language Support
private int ip_Language = 1; // English
private int ip_MonthDayPattern= 1; // DD.MM.YYY / DD/MM./YYYY
private string[] s_DayOfWeek;
private string[] s_MonthsOfYear;
public int DayOfWeekC = 2; // Amount of Chars for Day name
private string s_Today = "Today";
private DayOfWeek dow_FirstDayOfWeek;
/// <summary>
/// Language Support
/// - I am using the Telefon Codes for the Languages
/// - unsupported languages are defaulted to English
/// - Date Formatting is Maschine specific
/// - I hope that all formats are supported
/// </summary>
public int i_Language
{
get
{
return ip_Language;
}
set
{
//-- Support for MonthDayPattern needed in InitMonthContextMenu()
// - this is Maschine specific
System.Globalization.CultureInfo uici =
(CultureInfo)System.Globalization.CultureInfo.CurrentUICulture.Clone();
if (uici.DateTimeFormat.MonthDayPattern == "MMMM dd") // US-English and
Swahili(Kenia)
ip_MonthDayPattern= 0; // Month Day Year
if (uici.DateTimeFormat.MonthDayPattern == "dd MMMM") // Most of the
World
ip_MonthDayPattern= 1; // Day Month Year
if ((uici.DateTimeFormat.MonthDayPattern == "d MMMM") || // Polish
(uici.DateTimeFormat.MonthDayPattern == "MMMM d.") || // Hungray
(uici.DateTimeFormat.MonthDayPattern == "d. MMMM") || //
Lettland
(uici.DateTimeFormat.MonthDayPattern == "'den 'd MMMM")) // Sweden
ip_MonthDayPattern= 2; // Year Month Day
String s_Day = "";
// This should show Monday on a German Machine, but shows Sunday which
is not correct.
// - used only here and in CalculateFirstDate()
dow_FirstDayOfWeek = DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek;
// Add your Language here to support the Default
if ((value == 1) || (value == 49))
{
ip_Language = value;
}
else
{ // Set to English if Language is not supported
ip_Language = 1;
}
// Add your Language here to support DayOfWeek and Today, no other
changes are needed.
if (ip_Language == 1) // English
{
s_Today = "Today";
}
if (ip_Language == 49) // German
{
s_Today = "Heute";
// DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek does not work, so set
it Manually
/*
dow_FirstDayOfWeek = DayOfWeek.Tuesday;
dow_FirstDayOfWeek = DayOfWeek.Wednesday;
dow_FirstDayOfWeek = DayOfWeek.Thursday;
dow_FirstDayOfWeek = DayOfWeek.Friday;
dow_FirstDayOfWeek = DayOfWeek.Saturday;
dow_FirstDayOfWeek = DayOfWeek.Sunday;
*/
dow_FirstDayOfWeek = DayOfWeek.Monday;
}
// Set the Month to look at in the Year 2004.
int i_Month = 5;
if (dow_FirstDayOfWeek == DayOfWeek.Thursday)
{
i_Month = 1; // 01.01.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Friday)
{
i_Month = 10; // 01.10.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Saturday)
{
i_Month = 5; // 01.05.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Sunday)
{
i_Month = 2; // 01.02.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Monday)
{
i_Month = 3; // 01.03.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Tuesday)
{
i_Month = 6; // 01.06.2004
}
if (dow_FirstDayOfWeek == DayOfWeek.Wednesday)
{
i_Month = 9; // 01.09.2004
}
// Get the letters of the Days of the Week, accourding the
FirstDayofWeek Value
s_DayOfWeek = new string[7];
for (int i=1;i<=7;i++)
{
if (ip_MonthDayPattern == 0)
s_Day =
DateTime.Parse(string.Format("{0}/{1}/2004",i_Month,i)).ToString("dddd");
if (ip_MonthDayPattern == 1)
s_Day =
DateTime.Parse(string.Format("{1}/{0}/2004",i_Month,i)).ToString("dddd");
if (ip_MonthDayPattern == 2)
s_Day =
DateTime.Parse(string.Format("2004/{0}/{1}",i_Month,i)).ToString("dddd");
s_DayOfWeek[i-1] = s_Day.Substring(0,DayOfWeekC);
}
// Get the Months of Year , accourding the MonthNames Array
s_MonthsOfYear = new string[12];
for (int i=0;i<12;i++)
{
s_MonthsOfYear
= uici.DateTimeFormat.MonthNames;
}
} // set
} // public int i_Language
#endregion
private void DrawDaysOfWeek(Graphics g)
{ // mj10777 Language support
// calculate where to draw days of week
Point pos = new Point(Const.DaysGrid.X+3, Const.CaptionHeight);
// go through and draw each character
for (int i=0;i<s_DayOfWeek.Length;i++)
{
g.DrawString(s_DayOfWeek,m_fontCaption,m_brushCaptionBack,pos.X,pos.Y);
pos.X += Const.DaysCell.Width;
}
// separator line
g.DrawLine(m_penFrame, Const.DaysGrid.X, Const.DaysGrid.Y-1,
this.Width - Const.DaysGrid.X, Const.DaysGrid.Y-1);
} // private void DrawDaysOfWeek(Graphics g)
private void DrawBottomLabels(Graphics g)
{// mj10777 Language Support
// draw today string, don't store bounding rectangle since
// hit testing is the entire width of the calendar
string text = string.Format("{0}: {1}",s_Today,
m_today.ToShortDateString());
g.DrawString(text, this.m_fontCaption, this.m_brushCur,
Const.BottomLabelsPos.X, Const.BottomLabelsPos.Y);
} // private void DrawBottomLabels(Graphics g)
private void InitMonthContextMenu()
{ // mj10777 Language Support
// create a menu that contains list of months
m_monthMenu = new ContextMenu();
for (int i=0;i<12;i++)
{
// create new menu item and hookup the click event
MenuItem item = new MenuItem();
m_monthMenu.MenuItems.Add(item);
item.Click += new EventHandler(OnMonthMenuClick);
item.Text = s_MonthsOfYear;
}
// hookup popup event so can check the current month
m_monthMenu.Popup += new EventHandler(OnMonthMenuPopup);
} // private void InitMonthContextMenu()
private void CalculateFirstDate()
{ // mj10777 Language Support for dow_FirstDayofWeek used only here,
Checked : So,Mo,Tu,We,Th,Fr,Sa
m_firstDate = new DateTime(m_curSel.Year,m_curSel.Month,1);
int i_CountDays = 0;
if (m_firstDate.DayOfWeek == dow_FirstDayOfWeek)
i_CountDays = -7;
else
{
int i_FirstDayOfWeek = (int)dow_FirstDayOfWeek;
if ((int)m_firstDate.DayOfWeek != 0) // Not Sunday
{
i_CountDays = -(int)m_firstDate.DayOfWeek+i_FirstDayOfWeek;
if (i_CountDays > 0)
i_CountDays = -7+i_CountDays;
if (i_CountDays <= -7)
i_CountDays += 7;
}
else // Sunday
i_CountDays = -7+i_FirstDayOfWeek;
}
m_firstDate = m_firstDate.AddDays(i_CountDays); // Set the FirstDate
} // private void CalculateFirstDate()
}
Mark Johnson, Berlin Germany
(e-mail address removed)
bic said:
"Mark Johnson" <
[email protected]> wrote in message
Yes, this would interest me (E-Mail is below).
Since the Original version does not work at all on an non US-Cultures (like
Canada/UK-English,German) where the short date is not MM/DD/YYY, I would
like to keep this up to date (the month list shows 12 months with "January"
in the native Language).
This is why my last version can be downloaded from
http://www.mj10777.de/NETFramework/Compact/DateTimePicker/index.htm
I just saw that Canada has a special rule which made it not work in my
version.
The correction of this even simplyfies to code using
uici.DateTimeFormat.MonthNames
; to fill the Month MenuItems which would
solve most of problems of the non-US Cultures if used in the original code.
The only thing that must be hardcoded is "Today" and the FirstDayof Week
(when not Sunday) due to
DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek not working on Compact.
My Version also supports Mo, Tu etc. in the native Language when desired.
Mark Johnson, Berlin Germany
(e-mail address removed)
Do you plan on releasing a vb.net version.. This control seems so needed..
I hope microsoft release a proper version in the next CF.