Skip to content

Commit

Permalink
Allow runtime icon changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisdb2009 committed Aug 22, 2023
1 parent dafe203 commit d037175
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
20 changes: 18 additions & 2 deletions SuperGrate/Controls/Components/SGButton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
Expand All @@ -8,8 +9,23 @@ namespace SuperGrate.Controls.Components
{
public class SGButton : System.Windows.Forms.Button
{
private string rIcon = "";
[Browsable(true)]
public string Icon { get; set; }
public string Icon
{
get
{
return rIcon;
}
set
{
rIcon = value;
if (Button.Template == null) return;
System.Windows.Controls.Label icon = (System.Windows.Controls.Label)Button.Template.FindName("BtnIcon", Button);
if (icon == null) return;
icon.Content = rIcon;
}
}
private System.Windows.Controls.Button Button = new System.Windows.Controls.Button();
public SGButton()
{
Expand All @@ -24,7 +40,7 @@ public SGButton()
}
private void Button_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
((System.Windows.Controls.Label)Button.Template.FindName("BtnIcon", Button)).Content = Icon;
((System.Windows.Controls.Label)Button.Template.FindName("BtnIcon", Button)).Content = rIcon;
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
Expand Down
1 change: 0 additions & 1 deletion SuperGrate/Controls/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions SuperGrate/Controls/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public RunningTask Running {
{
Logger.UpdateProgress(0);
btnStartStop.Text = Language.Get("Control/Main/Stop");
btnStartStop.SetSystemIcon(Properties.Resources.cancel_ico);
btnStartStop.Icon = "";
Cursor = Cursors.AppStarting;
Misc.MainMenuSetState(MainMenu, false, new string[] { "&View" });
storeRunningTask = value;
Expand All @@ -224,7 +224,7 @@ public RunningTask Running {
{
Logger.UpdateProgress(-1);
btnStartStop.Text = Language.Get("Control/Main/Start");
btnStartStop.SetSystemIcon(Properties.Resources.go_ico);
btnStartStop.Icon = "";
Cursor = Cursors.Default;
Misc.MainMenuSetState(MainMenu, true);
storeRunningTask = value;
Expand Down

0 comments on commit d037175

Please sign in to comment.