C# | Create Dark & Light Theme Funcationality In Window Form Application.

C# | Create Dark & Light Funcationality In Window Form Application.

In this article we will see how to create dark & light theme funcationality in window form application.

First of all Create a windows forms in your project.

C# | Create Dark & Light Funcationality In Window Form Application.

Go to ToolBox and select or search pictureBox and add two pictureBox in your window form first for dark mode and second for light mode.

C# | Create Dark & Light Funcationality In Window Form Application.

After add pictureBoxes in your window form import dark mode images to Picturebox1 and light mode images to picturebox2.

After importing images in your pictureBoxes select stretchImage for fit your images in your pictureBoxes.

C# | Create Dark & Light Funcationality In Window Form Application.

By default light mode toggle image in unvisible.

Example for dark mode toggle image :

using System;
using System.Drawing;
using System.Windows.Forms;

namespace getsolutionhubDemo
{
    public partial class darkLightTheme : Form
    {
        public darkLightTheme()
        {
            InitializeComponent();
        }

        private void darkMode_Click(object sender, EventArgs e)
        {
            lightMode.Visible = true;
            darkMode.Visible = false;  
            this.BackColor = Color.Black;
            txtMsg.Text = "Dark Mode Enabled";
            txtMsg.ForeColor= Color.White;
        }
    }
}

Example for light mode toggle image :

using System;
using System.Drawing;
using System.Windows.Forms;

namespace getsolutionhubDemo
{
    public partial class darkLightTheme : Form
    {
        public darkLightTheme()
        {
            InitializeComponent();
        }

        private void lightMode_Click(object sender, EventArgs e)
        {
            darkMode.Visible = true;
            lightMode.Visible = false;
            this.BackColor = Color.White;
            txtMsg.Text = "Light Mode Enabled";
            txtMsg.ForeColor= Color.Black;
        }
    }
}

Output:

C# | Create Dark & Light Funcationality In Window Form Application.

Post a Comment

0 Comments