PDA

View Full Version : سوال: تغییر تاریخ میلادی به شمسی در DatePicker سی شارپ



MahmoodM30
شنبه 18 دی 1395, 12:53 عصر
سلام دوستان میخواستم ببینم چطوری میشه دیتاپیکر خود ی شارپ رو از میلادی به شمسی تغییر داد من یه کدی دارم میشه باهاش دیتاپیکرمیلادی تلریک رو راحت به شمسی تغییر داد حالا میخواستم ببینم میشه با تغییر این کد ها این کار رو برای دیتاپیکر خود سی شارپ هم کرد یا نه ممنون از راهنمایی های دوستان

این کد توی کلاس Program نوشته میشه


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Net;
using System.Globalization;
using System.Reflection;

namespace ProjectAriyaHesabdari1._0
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>

[STAThread]
static void Main()
{
ChangeCulture();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new MyContext());
}

private static void ChangeCulture()
{
CultureInfo c = new CultureInfo("fa-Ir");
var info = c.DateTimeFormat;

var p = info.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
p.SetValue(c.DateTimeFormat, new PersianCalendar());

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;
info.ShortestDayNames = new string[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };

System.Threading.Thread.CurrentThread.CurrentCultu re = c;
System.Threading.Thread.CurrentThread.CurrentUICul ture = c;
}

public class MyContext : ApplicationContext
{
public MyContext()
{
Application.Idle += new EventHandler(Application_Idle);
Agsat f1 = new Agsat();
f1.Show();
}
void Application_Idle(object sender, EventArgs e)
{
if (Application.OpenForms.Count == 0)
Application.Exit();
}
}
}
}