简体   繁体   中英

VB.NET MyApplication equivalent in c#

in my vb.Net Project I have used below code for setting date format of MyApplication

Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
        Dim newculture As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture.Clone()
        newculture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
        newculture.DateTimeFormat.DateSeparator = "/"
        System.Threading.Thread.CurrentThread.CurrentCulture = newculture
End Sub

How I can do this in c#??

In the file Program.cs you have static void Main() , where you can initialize application settings.

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Application.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
        Application.CurrentCulture.DateTimeFormat.DateSeparator = "/";

        Application.Run(new MainForm());
    }
private void MyApplication_Startup(object sender, Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
    System.Globalization.CultureInfo newculture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
    newculture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
    newculture.DateTimeFormat.DateSeparator = "/";
    System.Threading.Thread.CurrentThread.CurrentCulture = newculture;
}

try online converter for your help like below.

http://www.developerfusion.com/tools/convert/vb-to-csharp/

your code converted from the same.

private void MyApplication_Startup(object sender, Microsoft.VisualBasic.ApplicationServices.StartupEventArgs e)
{
    System.Globalization.CultureInfo newculture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
    newculture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
    newculture.DateTimeFormat.DateSeparator = "/";
    System.Threading.Thread.CurrentThread.CurrentCulture = newculture;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM