179 lines
6.3 KiB
C#
179 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using DisplLanguage = Test_MultilanguageUserControl.Languages.Language;
|
|
using MyControl;
|
|
|
|
namespace Test_MultilanguageUserControl
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
#region Version und Copyright
|
|
// Version und Copyright
|
|
string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen
|
|
string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
|
string copyright = GenerateCopyright();
|
|
string icon = Application.StartupPath + "\\Info.bmp";
|
|
//Assembly Datum und Zeit
|
|
static DateTime value = AssemblyDateTime();
|
|
string date = value.ToShortDateString();
|
|
string time = value.ToLongTimeString();
|
|
private static DateTime AssemblyDateTime()
|
|
{
|
|
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
|
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
|
//Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original)
|
|
return buildDateTime;
|
|
}
|
|
|
|
private static string CurrentYear()
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
|
|
private static string StartYear()
|
|
{
|
|
string startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
return startYear.Remove(0, startYear.LastIndexOf(" ") + 1);
|
|
}
|
|
|
|
private static string GenerateCopyright()
|
|
{
|
|
string startYear = StartYear();
|
|
string currentYear = CurrentYear();
|
|
|
|
if (startYear == currentYear)
|
|
{
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
|
}
|
|
else
|
|
{
|
|
return String.Concat(((AssemblyCopyrightAttribute)attributes[0]).Copyright, "-", currentYear);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Programm-Info
|
|
/// <summary>
|
|
/// Contains the name of the program file
|
|
/// </summary>
|
|
public static string ProgramName { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the version of the program file
|
|
/// </summary>
|
|
public static string ProgramVersion { set; get; }
|
|
|
|
/// <summary>
|
|
/// Contains the copyright notice
|
|
/// </summary>
|
|
public static string Copyright { set; get; }
|
|
|
|
private void SetProgramInfo()
|
|
{
|
|
//Name, Version und Copyright setzen
|
|
ProgramName = programName;
|
|
ProgramVersion = programVersion;
|
|
Copyright = copyright;
|
|
}
|
|
#endregion
|
|
public Form1()
|
|
{
|
|
SetProgramInfo();
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region Language
|
|
//DisplLanguage language;
|
|
|
|
//private void ChangeLanguage(string lang)
|
|
//{
|
|
// Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
|
|
// ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1));
|
|
// resources.ApplyResources(this, "$this");
|
|
// ApplyResources(resources, this.Controls);
|
|
//}
|
|
|
|
//private void ApplyResources(ComponentResourceManager resources, Control.ControlCollection ctls)
|
|
//{
|
|
// //all controls
|
|
// foreach (Control ctl in ctls)
|
|
// {
|
|
// resources.ApplyResources(ctl, ctl.Name);
|
|
// ApplyResources(resources, ctl.Controls);
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
#region Language1
|
|
///// <summary>
|
|
///// Change language at runtime in the specified form
|
|
///// </summary>
|
|
//internal static void SetLanguage(this Form form, CultureInfo lang)
|
|
//{
|
|
// //Set the language in the application
|
|
// System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
|
|
|
|
// ComponentResourceManager resources = new ComponentResourceManager(form.GetType());
|
|
|
|
// ApplyResourceToControl(resources, form.MainMenuStrip, lang);
|
|
// ApplyResourceToControl(resources, form, lang);
|
|
|
|
// //resources.ApplyResources(form, "$this", lang);
|
|
// form.Text = resources.GetString("$this.Text", lang);
|
|
//}
|
|
|
|
private void ApplyResourceToControl(ComponentResourceManager resources, Control control, CultureInfo lang)
|
|
{
|
|
foreach (Control c in control.Controls)
|
|
{
|
|
ApplyResourceToControl(resources, c, lang);
|
|
//resources.ApplyResources(c, c.Name, lang);
|
|
string text = resources.GetString(c.Name + ".Text", lang);
|
|
if (text != null)
|
|
c.Text = text;
|
|
}
|
|
}
|
|
|
|
private void ApplyResourceToControl(ComponentResourceManager resources, MenuStrip menu, CultureInfo lang)
|
|
{
|
|
foreach (ToolStripItem m in menu.Items)
|
|
{
|
|
//resources.ApplyResources(m, m.Name, lang);
|
|
string text = resources.GetString(m.Name + ".Text", lang);
|
|
if (text != null)
|
|
m.Text = text;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void radioButtonGerman_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
//language = DisplLanguage.German;
|
|
//Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de");
|
|
//ChangeLanguage("de");
|
|
|
|
//SetLanguage(this, "de");
|
|
}
|
|
|
|
private void radioButtonEnglish_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
//language = DisplLanguage.English;
|
|
//Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en");
|
|
//ChangeLanguage("en");
|
|
}
|
|
}
|
|
}
|