287 lines
11 KiB
C#
287 lines
11 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
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 Eugen.ESystem.Windows.Forms;
|
|
|
|
namespace SearchFindReplace
|
|
{
|
|
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);
|
|
string startYear = "";
|
|
if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © "))
|
|
{
|
|
startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", "");
|
|
while (startYear.StartsWith(" "))
|
|
{
|
|
startYear = startYear.Remove(0, 1);
|
|
}
|
|
startYear = startYear.Remove(startYear.IndexOf(" "));
|
|
return startYear;
|
|
}
|
|
else
|
|
{
|
|
DateTime dtn = DateTime.Now;
|
|
return dtn.Year.ToString();
|
|
}
|
|
}
|
|
|
|
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);
|
|
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", 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(); //Name, Version und Copyright setzen
|
|
|
|
InitializeComponent();
|
|
|
|
//Systemsprache auslesen und Programmsprache setzen oder ...
|
|
if (Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName == "de")
|
|
{
|
|
SetLanguage("Deutsch", CultureInfo.GetCultureInfo("de"));
|
|
}
|
|
else
|
|
{
|
|
SetLanguage("English", CultureInfo.GetCultureInfo("en"));
|
|
}
|
|
|
|
//... oder Programmsprache definitiv auf "Deutsch" setzen
|
|
SetLanguage("Deutsch", CultureInfo.GetCultureInfo("de"));
|
|
|
|
//Dll-Informationen laden
|
|
LoadDllInfo();
|
|
}
|
|
|
|
private void SetLanguage(string language, CultureInfo languageShortForm)
|
|
{
|
|
CultureInfoDisplayItem cidi = (CultureInfoDisplayItem)new CultureInfoDisplayItem(language, languageShortForm);
|
|
FormLanguageSwitchSingleton.Instance.ChangeLanguage(this, cidi.CultureInfo);
|
|
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(languageShortForm.ToString());
|
|
ChangeLanguage(languageShortForm.ToString());
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
//the menu bar and its items
|
|
foreach (ToolStripItem item in menuStrip.Items)
|
|
{
|
|
if (item is ToolStripDropDownItem)
|
|
{
|
|
resources.ApplyResources(item, item.Name);
|
|
foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
|
|
{
|
|
resources.ApplyResources(dropDownItem, dropDownItem.Name);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MarkCurrentLanguage()
|
|
{
|
|
deutschToolStripMenuItem.Checked = !deutschToolStripMenuItem.Checked;
|
|
englischToolStripMenuItem.Checked = !englischToolStripMenuItem.Checked;
|
|
if (radioButtonGerman.Checked)
|
|
{
|
|
radioButtonEnglish.Checked = true;
|
|
}
|
|
else
|
|
{
|
|
radioButtonGerman.Checked = true;
|
|
}
|
|
}
|
|
|
|
private void LoadDllInfo()
|
|
{
|
|
string dllInfo = "";
|
|
dllInfo = String.Concat(FormLanguageSwitchSingleton.DllName, ": ", FormLanguageSwitchSingleton.DllVersion, "\n\r", FormLanguageSwitchSingleton.Copyright, "\n\r");
|
|
dllInfo = String.Concat(dllInfo, Search.DllName, ": ", Search.DllVersion, "\n\r", Search.Copyright, "\n\r");
|
|
dllInfo = String.Concat(dllInfo, Replace.DllName, ": ", Replace.DllVersion, "\n\r", Replace.Copyright);
|
|
labelDllInfo.Text = dllInfo;
|
|
labelDllInfo.Refresh();
|
|
}
|
|
|
|
private void buttonCheckLanguage_Click(object sender, EventArgs e)
|
|
{
|
|
MessageBox.Show(String.Concat(Resources.mbt000text, Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName), Resources.mbt000caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
private void radioButtonGerman_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SetLanguage("Deutsch", CultureInfo.GetCultureInfo("de"));
|
|
|
|
LoadDllInfo();
|
|
}
|
|
|
|
private void radioButtonEnglish_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
SetLanguage("Englisch", CultureInfo.GetCultureInfo("en"));
|
|
|
|
LoadDllInfo();
|
|
}
|
|
|
|
private void deutschToolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
SetLanguage("Deutsch", CultureInfo.GetCultureInfo("de"));
|
|
MarkCurrentLanguage();
|
|
|
|
LoadDllInfo();
|
|
}
|
|
|
|
private void englischToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
SetLanguage("Englisch", CultureInfo.GetCultureInfo("en"));
|
|
MarkCurrentLanguage();
|
|
|
|
LoadDllInfo();
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
//--- Diesen Bereich ins eigene Programm einfügen --- Anfang ---
|
|
//--------------------------------------------------------------
|
|
// Die Zeile "using Eugen.ESystem.Windows.Forms;" einfügen
|
|
// Die Verweise "SearchString" und "ReplaceString" einfügen
|
|
//--------------------------------------------------------------
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
search1.SetSearchText(textBoxText.Text); //Text aus der Textbox übergeben
|
|
search1.RefreshDisplay += new Search.RefreshDelegate(RefreshDisplay); //Hier wird das Event abonniert
|
|
search1.InputChanged += new Search.InputChangedDelegate(InputChanged); //Hier wird das Event abonniert
|
|
|
|
replace1.SetSearchText(textBoxText.Text); //Text aus der Textbox übergeben
|
|
replace1.StringFound += new Replace.EventDelegate(RefreshDisplay); //Hier wird das Event abonniert
|
|
}
|
|
catch (IncompleteInputException)
|
|
{
|
|
MessageBox.Show("Eingabe unvollständig!");
|
|
}
|
|
catch (StringNotMatchException)
|
|
{
|
|
MessageBox.Show("Keine (weitere) Übereinstimmung gefunden!");
|
|
}
|
|
}
|
|
|
|
//Zeichnet die TextBox neu
|
|
void RefreshDisplay(int currentCursorPosition, int searchStringLenght)
|
|
{
|
|
RefreshTextBox(currentCursorPosition, searchStringLenght); //Ansicht aktualisieren
|
|
}
|
|
|
|
//Trifft zu wenn sich die Eingabe geändert hat
|
|
void InputChanged()
|
|
{
|
|
replace1.SetMoreMatch(true); //Gibt der Replace Funktion bekannt, dass es weitere Treffer gibt
|
|
}
|
|
|
|
private void RefreshTextBox(int currentCursorPosition, int searchStringLenght)
|
|
{
|
|
//Ansicht aktualisieren
|
|
textBoxText.Text = search1.GetSearchText(); //Aktuellen Text zuweisen
|
|
textBoxText.Focus(); //Focus auf die Textbox
|
|
textBoxText.Select(currentCursorPosition, searchStringLenght); //Suchstring in der Textbox selektieren
|
|
textBoxText.Refresh();
|
|
}
|
|
|
|
//--------------------------------------------------------------
|
|
//--- Diesen Bereich ins eigene Programm einfügen --- Ende ---
|
|
//--------------------------------------------------------------
|
|
}
|
|
}
|