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.
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.
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.
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;
}
}
}
0 Comments
Enter Your Comment