Skip to content

Theme Changes #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions IconMapper/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
</startup>
<appSettings>
<add key="IconFolderPath" value="C:\Path\To\Your\Icons"/>
<add key="LastTheme" value ="0"/>
</appSettings>
</configuration>
45 changes: 45 additions & 0 deletions IconMapper/ContextMenuOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IconMapper
{
class ContextMenuOptions
{
public static void contextMenuOptions()
{
// Define the folder containing the icon files
string iconDirectory = @"C:\Path\To\Your\IconFolder";
string contextMenuPath = @"HKEY_CLASSES_ROOT\Directory\shell\ChangeIcon\submenus";

if (Directory.Exists(iconDirectory))
{
// Scan the directory for .ico files
string[] icoFiles = Directory.GetFiles(iconDirectory, "*.ico");

// Create registry key for sub-menu
foreach (var iconFile in icoFiles)
{
string iconName = Path.GetFileNameWithoutExtension(iconFile);

// Add a new key for each icon file in the submenus
string iconRegistryPath = contextMenuPath+"\\"+iconName;

// Create a registry entry for each .ico file
Registry.SetValue(iconRegistryPath, "", iconName);
Registry.SetValue(iconRegistryPath+"\\command", "", "C:\\Path\\To\\YourApp\\ChangeIconApp.exe\" \"%1\" \"{iconFile}\"");

Console.WriteLine("Added {iconFile} to context menu.");
}
}
else
{
Console.WriteLine("The directory '{iconDirectory}' does not exist.");
}
}
}
}
18 changes: 15 additions & 3 deletions IconMapper/Form/MainForm.Designer.cs

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

144 changes: 137 additions & 7 deletions IconMapper/Form/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,86 @@ namespace IconMapper
public partial class MainForm : Form
{
private string selectedIconPath;
private enum Theme { Light, Dark };
Theme themeselected = Theme.Light;

/// <summary>
/// Main Form
/// </summary>
public MainForm()
{
InitializeComponent();
themeselected = (Theme)Convert.ToInt32(ConfigurationManager.AppSettings["LastTheme"]);
setTheme(themeselected);
LoadDrives();
LoadIcons();
}

/// <summary>
/// Dark Theme
/// </summary>
private void DarkTheme()
{
// Background and Foreground
this.BackColor = Color.FromArgb(30, 30, 30); // Dark theme
this.ForeColor = Color.White;

// TreeView Styling
folderTreeView.BackColor = Color.FromArgb(45, 45, 48);
folderTreeView.ForeColor = Color.White;
folderTreeView.BorderStyle = BorderStyle.FixedSingle;

// ListBox Styling
iconListBox.BackColor = Color.FromArgb(40, 40, 42);
iconListBox.ForeColor = Color.LightGreen;
iconListBox.BorderStyle = BorderStyle.FixedSingle;

// PictureBox Styling (border if needed)
iconPreviewPictureBox.BackColor = Color.FromArgb(50, 50, 50);
iconPreviewPictureBox.BorderStyle = BorderStyle.FixedSingle;

// Apply Button Styling (if you use a button called applyIconButton)
applyIconButton.BackColor = Color.FromArgb(70, 130, 180); // SteelBlue
applyIconButton.ForeColor = Color.White;
applyIconButton.FlatStyle = FlatStyle.Flat;
applyIconButton.FlatAppearance.BorderColor = Color.White;
applyIconButton.FlatAppearance.BorderSize = 1;

DirectoryFinder.ForeColor = Color.White;
IconBox.ForeColor = Color.White;

themeselected = Theme.Dark;
}

/// <summary>
/// Light Theme (Default)
/// </summary>
private void LightTheme()
{
// Standard Theme
//this.DoubleBuffered = true;
DirectoryFinder.ForeColor = Color.Black;
IconBox.ForeColor = Color.Black;

this.ForeColor = SystemColors.ControlText;
this.BackColor = SystemColors.Control;

folderTreeView.ForeColor = SystemColors.ControlText;
folderTreeView.BackColor = SystemColors.Control;

applyIconButton.ForeColor = SystemColors.ControlText;
applyIconButton.BackColor = SystemColors.Control;

iconListBox.ForeColor = SystemColors.ControlText;
iconListBox.BackColor = SystemColors.Control;

iconPreviewPictureBox.BackColor = SystemColors.Control;
iconPreviewPictureBox.BorderStyle = BorderStyle.None;

themeselected = Theme.Light;
}


/// <summary>
/// Loads the available drives and adds them to the TreeView.
/// </summary>
Expand Down Expand Up @@ -248,6 +320,13 @@ private void RefreshFolderView()
SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
}

/// <summary>
/// Folder Refresh
/// </summary>
/// <param name="wEventId"></param>
/// <param name="uFlags"></param>
/// <param name="dwItem1"></param>
/// <param name="dwItem2"></param>
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
private static extern void SHChangeNotify(int wEventId, int uFlags, IntPtr dwItem1, IntPtr dwItem2);

Expand Down Expand Up @@ -309,17 +388,16 @@ protected override void OnResize(EventArgs e)
/// <param name="e"></param>
private void SettingsMenuItem_Click(object sender, EventArgs e)
{
string selectedPath = string.Empty;
using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
{
if (folderDialog.ShowDialog() == DialogResult.OK)
{
string selectedPath = folderDialog.SelectedPath;
// Update app.config with the new path
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["IconFolderPath"].Value = selectedPath;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
MessageBox.Show("Icon folder path updated successfully.");
selectedPath = folderDialog.SelectedPath;

if (UpdateConfig("IconFolderPath", selectedPath))
MessageBox.Show("Icon folder path updated successfully.");

}
}
}
Expand Down Expand Up @@ -388,5 +466,57 @@ private void AboutMenuItem_Click(object sender, EventArgs e)
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

/// <summary>
/// Change Theme from Menu
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void changeThemeToolStripMenuItem_Click(object sender, EventArgs e)
{
themeselected = themeselected == Theme.Light ? Theme.Dark : Theme.Light;
setTheme(themeselected);

UpdateConfig("LastTheme", Convert.ToString(Convert.ToInt32(themeselected)));

}

/// <summary>
/// Set Theme for the Application
/// </summary>
/// <param name="theme"></param>
private void SetApplicationTheme(Theme theme)
{
if (themeselected == Theme.Light)
LightTheme();
else
DarkTheme();
}

/// <summary>
/// Update Cofig File
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <param name="section"></param>
/// <returns></returns>
private bool UpdateConfig(string key, string value, string section = "appSettings")
{
bool retValue = false;
try
{
// Update app.config with the new path
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(section);
}
catch (Exception ex)
{

}

return retValue;
}
}
}
Binary file added IconMapper/Icon/dark_mode_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IconMapper/Icon/light_mode_24dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added IconMapper/Icon/themes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions IconMapper/IconMapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContextMenuOptions.cs" />
<Compile Include="Helper\ConfigHelper.cs" />
<Compile Include="Form\MainForm.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -100,6 +101,7 @@
<ItemGroup>
<Content Include="Icon\IconMapper.ico" />
<Content Include="Icon\IconMapper_48.ico" />
<None Include="Icon\themes.png" />
<None Include="Icon\upload_24dp.png" />
<None Include="Icon\settings_24dp.png" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions IconMapper/Properties/Resources.Designer.cs

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

7 changes: 5 additions & 2 deletions IconMapper/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,13 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="upload_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\upload_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="settings_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\settings_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="upload_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\upload_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="themes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Icon\themes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>