//============================================================================
// WMIInfo 2.0
// Copyright � 2009 Stephan Berger
//
//This file is part of WMIInfo.
//
//WMIInfo is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//WMIInfo is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with WMIInfo. If not, see <http://www.gnu.org/licenses/>.
//
//============================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WMIInfo
{
public partial class Form2 : Form
{
private Form1 f1;
int[] _functionOrder = new int[20];
string[] sTitle = new string[20];
bool[] bLBr = new bool[20];
//public bool[] iLBHist = new bool[20];
//public string[] sTitleHist = new string[20];
public Form2(Form1 _ref)
{
InitializeComponent();
this.f1 = _ref; // der Form2 eine referenz auf Form1 uebergeben
}
private void Form2_Load(object sender, EventArgs e)
{
_setLocation();
settingsLoad();
}
private void _setLocation()
{
Size sScreen = Screen.PrimaryScreen.Bounds.Size;
Size iLSize = f1.Size;
Size iFSize = this.Size;
Point pPos = f1.DesktopLocation;
if (pPos.X < sScreen.Width / 2) //linke H�lfte
{
if (pPos.Y < sScreen.Height / 2) //oben
this.SetDesktopLocation((sScreen.Width / 2) - iFSize.Width, (sScreen.Height / 2) - iFSize.Height); //
else
this.SetDesktopLocation((sScreen.Width / 2) - iFSize.Width, (sScreen.Height / 2));
}
else //rechte H�lfe
{
if (pPos.Y < sScreen.Height / 2) //oben
this.SetDesktopLocation((sScreen.Width / 2), (sScreen.Height / 2) - iFSize.Height);
else
this.SetDesktopLocation((sScreen.Width / 2), (sScreen.Height / 2));
}
}
private void settingsLoad()
{
_LBFill();
_initArrays();
colorbox.BackColor = Properties.Settings.Default.f1TextColor;
label4.Text = Properties.Settings.Default.f1Text.Name;
label4.Font = Properties.Settings.Default.f1Text;
timerIntervall.Value = Properties.Settings.Default.f2Timer;
}
private void _LBFill()
{
string sText;
string [] sDelim = { "\r\n" };
string[] sComboArr;
if(Properties.Settings.Default.lang == "de-DE")
sText = Properties.Settings.Default["f2LBAvailable"].ToString();
else
sText = Properties.Settings.Default["f2LBAvailable_GB"].ToString();
sComboArr = sText.Split(sDelim, StringSplitOptions.RemoveEmptyEntries);
lbAvailable.Items.AddRange(sComboArr);
sText = Properties.Settings.Default["f2LBActive"].ToString();
sComboArr = sText.Split(sDelim, StringSplitOptions.RemoveEmptyEntries);
lbActive.Items.AddRange(sComboArr);
}
private void _initArrays()
{
for (int i = 0; i < 20; i++)
{
int iFind = Array.IndexOf(f1.iFunction, i);
if (iFind > -1)
{
_functionOrder[i] = iFind;
sTitle[i] = f1.sTitle[iFind];
lbTitle.Items.Add(sTitle[i]);
bLBr[i] = f1.iLB[iFind];
//sTitleHist[i] = f1.sTitleHist[iFind];
//iLBHist[i] = f1.iLBHist[iFind];
}
else
{
_functionOrder[i] = -1;
sTitle[i] = "";
bLBr[i] = false;
}
}
}
private void cancel_Click(object sender, EventArgs e)
{
_user_save();
f1.settings_Load();
f1.settingsActivate();
Close();
Dispose();
}
private void button1_Click(object sender, EventArgs e) //Test
{
_TestSettings();
button2.Enabled = true;
f1.settingsActivate();
}
private void _TestSettings()
{
f1.lable.ForeColor = colorbox.BackColor;
f1.lable.Font = label4.Font;
for (int i = 0; i < 20; i++)
{
f1.iFunction[i] = Array.IndexOf(_functionOrder, i);
if (f1.iFunction[i] > -1)
{
f1.sTitle[i] = sTitle[f1.iFunction[i]];
f1.iLB[i] = bLBr[f1.iFunction[i]];
//f1.sTitleHist[i] = sTitleHist[f1.iFunction[i]];
//f1.iLBHist[i] = iLBHist[f1.iFunction[i]];
}
else
{
f1.sTitle[i] = "";
f1.iLB[i] = false;
}
}
}
private void button2_Click(object sender, EventArgs e) //R�cksetzen
{
button2.Enabled = false;
_resetSettings();
}
private void _resetSettings()
{
_user_save();
lbActive.Items.Clear();
lbAvailable.Items.Clear();
f1.settings_Load();
settingsLoad();
// _TestSettings();
f1.lable.ForeColor = Properties.Settings.Default.f1TextColor;
colorbox.BackColor = f1.lable.ForeColor;
f1.lable.Font = Properties.Settings.Default.f1Text;
f1.settingsActivate();
}
private void apply_Click(object sender, EventArgs e) //Anwenden
{
string sVar;
_TestSettings();
f1.timer1.Interval = Convert.ToInt16(timerIntervall.Value) * 1000;
for (int i = 0; i < 20; i++)
{
sVar = "f2Titel" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.sTitle[i];
sVar = "f2Funktion" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.iFunction[i];
sVar = "f2LB" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.iLB[i];
sVar = "f2TitelHist" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.sTitleHist[i];
sVar = "f2LBHist" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.iLBHist[i];
}
_LBSave();
Properties.Settings.Default.f1TextColor = colorbox.BackColor;
Properties.Settings.Default.f1Text = label4.Font;
Properties.Settings.Default.f2Timer = Convert.ToInt16(timerIntervall.Value);
Properties.Settings.Default.pXpos = f1.Location.X;
Properties.Settings.Default.pYpos = f1.Location.Y;
Properties.Settings.Default.Save();
while (!Properties.Settings.Default.IsSynchronized)
{
System.Threading.Thread.Sleep(500);
}
Close();
Dispose();
//f1.settings_Load();
f1.settingsActivate();
}
void Form2_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
f1.timer1.Enabled = true;
}
private void _LBSave()
{
string sText;
string[] sDelim = { "\r\n" };
string[] sComboArr = new string [20];
lbActive.Items.CopyTo(sComboArr,0);
sText = String.Join("\r\n",sComboArr);
Properties.Settings.Default.f2LBActive = sText;
}
private void colorbox_Click(object sender, EventArgs e)
{
_ColorSet();
}
private void button3_Click(object sender, EventArgs e)
{
_ColorSet();
}
private void _ColorSet()
{
colorDialog1.ShowDialog();
Color lColor = colorDialog1.Color;
Color black = Color.FromArgb(255,0,0,0);
if (lColor.ToArgb() != black.ToArgb())
colorbox.BackColor = lColor;
else
colorbox.BackColor = Color.FromArgb(255,0, 0, 1);
}
private void button4_Click(object sender, EventArgs e)
{
_FontSet();
}
private void label4_Click(object sender, EventArgs e)
{
_FontSet();
}
private void _FontSet()
{
fontDialog1.ShowDialog();
Font lFont = fontDialog1.Font;
label4.Text = lFont.Name;
label4.Font = lFont;
}
private void lbAvailable_SelectedIndexChanged(object sender, EventArgs e)
{
}
void lbAvailable_DoubleClick(object sender, System.EventArgs e)
{
if (!lbActive.Items.Contains(lbAvailable.SelectedItem))
{
lbActive.Items.Add(lbAvailable.SelectedItem);
lbTitle.Items.Add("");
_functionOrder[lbActive.Items.Count - 1] = lbAvailable.SelectedIndex;
}
}
void lbActive_DoubleClick(object sender, System.EventArgs e) //Funktion aus aktiver Liste l�schen
{
if (lbActive.SelectedIndex == lbActive.Items.Count-1)
{
sTitle[lbActive.SelectedIndex] = "";
bLBr[lbActive.SelectedIndex] = false;
_functionOrder[lbActive.SelectedIndex] = -1;
}
else
{
for (int i = lbActive.SelectedIndex; i < 19; i++)
{
sTitle[i] = sTitle[i+1];
bLBr[i] = bLBr[i+1];
_functionOrder[i] = _functionOrder[i+1];
}
sTitle[19] = "";
bLBr[19] = false;
_functionOrder[19] = -1;
}
if (lbTitle.Items.Count > lbActive.SelectedIndex)
lbTitle.Items.RemoveAt(lbActive.SelectedIndex);
lbActive.Items.Remove(lbActive.SelectedItem);
}
void lbTitle_DoubleClick(object sender, System.EventArgs e) //Titletext entfernen
{
if (lbTitle.SelectedIndex > -1)
{
sTitle[lbTitle.SelectedIndex] = "";
lbTitle.Items.Insert(lbTitle.SelectedIndex, "");
if(lbTitle.Items.Count > lbTitle.SelectedIndex)
lbTitle.Items.RemoveAt(lbTitle.SelectedIndex);
textBox1.Text = "";
}
}
private void button5_Click(object sender, EventArgs e) //Titel f�r Funktion eintragen
{
if (lbActive.SelectedIndex > -1)
{
sTitle[lbActive.SelectedIndex] = textBox1.Text;
f1.sTitleHist[_functionOrder[lbActive.SelectedIndex]] = textBox1.Text;
if (lbTitle.Items.Count > lbActive.SelectedIndex)
lbTitle.Items.Insert(lbActive.SelectedIndex, textBox1.Text);
else
{
for (int i = lbTitle.Items.Count; i <= lbActive.SelectedIndex + 1; i++)
{
lbTitle.Items.Insert(i, "");
}
lbTitle.Items.Insert(lbActive.SelectedIndex, textBox1.Text);
}
if (lbTitle.Items.Count > lbActive.SelectedIndex + 1)
lbTitle.Items.RemoveAt(lbActive.SelectedIndex + 1);
}
else if (lbTitle.SelectedIndex > -1)
{
sTitle[lbTitle.SelectedIndex] = textBox1.Text;
f1.sTitleHist[_functionOrder[lbTitle.SelectedIndex]] = textBox1.Text;
lbTitle.Items.Insert(lbTitle.SelectedIndex, textBox1.Text);
if (lbTitle.Items.Count > lbTitle.SelectedIndex)
lbTitle.Items.RemoveAt(lbTitle.SelectedIndex);
}
else
MessageBox.Show("W�hlen Sie eine Funktion aus!");
}
private void lbActive_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbActive.SelectedIndex > -1)
{
if (sTitle[lbActive.SelectedIndex] != "")
{
textBox1.Text = sTitle[lbActive.SelectedIndex];
checkLBr.Checked = bLBr[lbActive.SelectedIndex];
}
else
{
try
{
textBox1.Text = f1.sTitleHist[_functionOrder[lbActive.SelectedIndex]];
checkLBr.Checked = f1.iLBHist[_functionOrder[lbActive.SelectedIndex]];
}
catch (Exception)
{
}
}
lbTitle.SelectedIndex = lbActive.SelectedIndex;
}
else
{
textBox1.Text = "";
checkLBr.Checked = false;
}
}
private void lbTitle_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbTitle.SelectedIndex > -1)
{
if (sTitle[lbTitle.SelectedIndex] != "")
{
textBox1.Text = sTitle[lbTitle.SelectedIndex];
checkLBr.Checked = bLBr[lbTitle.SelectedIndex];
}
else
{
try
{
textBox1.Text = f1.sTitleHist[_functionOrder[lbTitle.SelectedIndex]];
checkLBr.Checked = f1.iLBHist[_functionOrder[lbTitle.SelectedIndex]];
}
catch (Exception)
{
}
}
lbActive.SelectedIndex=lbTitle.SelectedIndex;
}
else
{
textBox1.Text = "";
checkLBr.Checked = false;
}
}
void checkLBr_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (lbActive.SelectedIndex > -1)
{
bLBr[lbActive.SelectedIndex] = checkLBr.Checked;
f1.iLBHist[_functionOrder[lbActive.SelectedIndex]] = checkLBr.Checked;
}
else if (lbTitle.SelectedIndex > -1)
{
bLBr[lbTitle.SelectedIndex] = checkLBr.Checked;
f1.iLBHist[_functionOrder[lbTitle.SelectedIndex]] = checkLBr.Checked;
}
}
private void checkLBr_CheckedChanged(object sender, EventArgs e)
{
}
private void _user_save()
{
string sVar;
for (int i = 0; i < 20; i++) //Eingaben f�r Titel und Zeilenumbruch merken
{
sVar = "f2TitelHist" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.sTitleHist[i];
sVar = "f2LBHist" + (i + 1).ToString();
Properties.Settings.Default[sVar] = f1.iLBHist[i];
}
}
private void bUp_Click(object sender, EventArgs e)
{
if(lbActive.SelectedIndex > 0)
{
string sBuffer = "",sTi_Sel,sTi_Next;
int iBuffer,iF_Sel,iF_Next;
bool bLBr_Sel, bLBr_Next;
sBuffer = lbActive.SelectedItem.ToString();
iBuffer = lbActive.SelectedIndex;
lbActive.Items.RemoveAt(iBuffer);
lbActive.Items.Insert(iBuffer - 1, sBuffer);
lbActive.SelectedIndex = iBuffer - 1;
sBuffer = lbTitle.Items[iBuffer].ToString();
lbTitle.Items.RemoveAt(iBuffer);
lbTitle.Items.Insert(iBuffer - 1,sBuffer);
lbTitle.SelectedIndex = iBuffer - 1;
iF_Sel = _functionOrder[iBuffer];
iF_Next = _functionOrder[iBuffer-1];
_functionOrder[iBuffer-1] = iF_Sel;
_functionOrder[iBuffer] = iF_Next;
sTi_Sel = sTitle[iBuffer];
sTi_Next = sTitle[iBuffer-1];
sTitle[iBuffer-1] = sTi_Sel;
sTitle[iBuffer] = sTi_Next;
bLBr_Sel = bLBr[iBuffer];
bLBr_Next = bLBr[iBuffer-1];
bLBr[iBuffer-1] = bLBr_Sel;
bLBr[iBuffer] = bLBr_Next;
}
}
private void bDown_Click(object sender, EventArgs e)
{
if(lbActive.SelectedIndex < lbActive.Items.Count-1)
{
string sBuffer = "",sTi_Sel,sTi_Next;
int iBuffer,iF_Sel,iF_Next;
bool bLBr_Sel, bLBr_Next;
sBuffer = lbActive.SelectedItem.ToString();
iBuffer = lbActive.SelectedIndex;
lbActive.Items.RemoveAt(iBuffer);
lbActive.Items.Insert(iBuffer + 1, sBuffer);
lbActive.SelectedIndex = iBuffer + 1;
sBuffer = lbTitle.Items[iBuffer].ToString();
lbTitle.Items.RemoveAt(iBuffer);
lbTitle.Items.Insert(iBuffer + 1,sBuffer);
lbTitle.SelectedIndex = iBuffer + 1;
iF_Sel = _functionOrder[iBuffer];
iF_Next = _functionOrder[iBuffer+1];
_functionOrder[iBuffer+1] = iF_Sel;
_functionOrder[iBuffer] = iF_Next;
sTi_Sel = sTitle[iBuffer];
sTi_Next = sTitle[iBuffer+1];
sTitle[iBuffer+1] = sTi_Sel;
sTitle[iBuffer] = sTi_Next;
bLBr_Sel = bLBr[iBuffer];
bLBr_Next = bLBr[iBuffer+1];
bLBr[iBuffer+1] = bLBr_Sel;
bLBr[iBuffer] = bLBr_Next;
}
}
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
}
private void fontDialog1_Apply(object sender, EventArgs e)
{
}
}
}