Stvar je sledeća:
U aplikaciji imam "customise" opciju (changing themes - uglavnom se smenjuju form icons, button images, picturebox images etc.) koja funkcioniše na sledeći način:
Kada se aplikacija startuje, proverava se koja je tema izabrana:
Code (csharp):
...gde je ThemeCheck():
Code (csharp):
void ThemeCheck()
{
if (Properties.Settings.Default.Theme == "Purple")
{
foreach (var form in Application.OpenForms.Cast<Form>())
{
form.Icon = Properties.Resources.Purple;
}
Main f1 = (Main)Application.OpenForms["Main"];
Settings f2 = (Settings)Application.OpenForms["Settings"];
f1.btn_Exit.Image = Properties.Resources.EXIT_purple;
}
if (Properties.Settings.Default.Theme == "Blue")
{
foreach (var form in Application.OpenForms.Cast<Form>())
{
form.Icon = Properties.Resources.Blue;
}
Main f1 = (Main)Application.OpenForms["Main"];
Settings f2 = (Settings)Application.OpenForms["Settings"];
f1.btn_Exit.Image = Properties.Resources.EXIT_blue;
}
}
void ThemeCheck()
{
if (Properties.Settings.Default.Theme == "Purple")
{
foreach (var form in Application.OpenForms.Cast<Form>())
{
form.Icon = Properties.Resources.Purple;
}
Main f1 = (Main)Application.OpenForms["Main"];
Settings f2 = (Settings)Application.OpenForms["Settings"];
f1.btn_Exit.Image = Properties.Resources.EXIT_purple;
}
if (Properties.Settings.Default.Theme == "Blue")
{
foreach (var form in Application.OpenForms.Cast<Form>())
{
form.Icon = Properties.Resources.Blue;
}
Main f1 = (Main)Application.OpenForms["Main"];
Settings f2 = (Settings)Application.OpenForms["Settings"];
f1.btn_Exit.Image = Properties.Resources.EXIT_blue;
}
}
itd. za svaku boju (ima ih 10, pa bi bilo nepotrebno da kopiram sve).
Uglavnom, to sve funkcioniše savršeno, ali problem nastaje kada se aplikacija resetuje. Gubi se izabrana tema i javlja se neka random (najčešće plava (blue) - nisam uspeo da provalim po kom principu baš ta, a nekad i ona default, tj. kako sam pravio aplikaciju - uglavnom gubi se ona izabrana tj. Properties.Settings.Default.Theme). Znači, želeo bih da tema koja je izabrana ostane i nakon restartovanja aplikacije. Npr, ako sam izabrao purple, želeo bih da ostane purple i nakon restartovanja.
Restartovanje sam probao na razne načine - i sa Application.Restart, a i na sledeći način:
Code (csharp):
void ResetThis()
{
listView1.Clear();
Settings f2 = new Settings();
Properties.Settings.Default.Theme = f2.combo_Theme.Text;
Properties.Settings.Default.Save();
Application.exit();
System.Diagnostics.Process.Start(Application.ExecutablePath);
ThemeCheck();
}
void ResetThis()
{
listView1.Clear();
Settings f2 = new Settings();
Properties.Settings.Default.Theme = f2.combo_Theme.Text;
Properties.Settings.Default.Save();
Application.exit();
System.Diagnostics.Process.Start(Application.ExecutablePath);
ThemeCheck();
}
Treba napomenuti da ne snimam settingse na ovaj način, to se vrši kada se podešavanja izvrše, prilikom gašenja forme gde se podešavanja vrše (form Settings). Znači, čak sam probao i da dva puta snimim settings - nakon gašenja forme Settings (gde se inače ta podešavanja vrše), a i nakon gašenja Main forme.
Ima li neko ideju kako da premostim problem?