VB.NET MyApplication相当于c#

时间:2013-04-05 10:24:16

标签: c# visual-studio

在我的vb.Net项目中,我使用下面的代码设置了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
  

我怎样才能在c#??

中做到这一点

3 个答案:

答案 0 :(得分:2)

在文件Program.cs中,您有static void Main(),您可以在其中初始化应用程序设置。

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

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

        Application.Run(new MainForm());
    }

答案 1 :(得分:-1)

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;
}

答案 2 :(得分:-2)

尝试在线转换器以获取您的帮助,如下所示。

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

你的代码是从同一个转换而来的。

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;
}