Introduction
Ever wanted to make your application look more like a Mac style application? Well, now you can in less than 50 lines of code! No DLLs required, just two images and some simple code. This is a great way for average beginners to add some style to their apps without having to use DLLs and a lot of code.
Background
Using the Code
Simply import the images into your project, then use the images in 2 picture boxes. One picturebox will have the unchecked image and the other should show the checked image.
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox2.Show();
pictureBox1.Hide();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
pictureBox2.Hide();
pictureBox1.Show();
}
private void pictureBox3_Click(object sender, EventArgs e)
{
pictureBox4.Show();
pictureBox3.Hide();
MessageBox.Show("Checked");
}
private void pictureBox4_Click(object sender, EventArgs e)
{
pictureBox4.Hide();
pictureBox3.Show();
MessageBox.Show("Unchecked");
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox2.Hide();
pictureBox2.Location = pictureBox1.Location;
pictureBox2.Size = pictureBox1.Size;
pictureBox4.Hide();
pictureBox4.Location = pictureBox3.Location;
pictureBox4.Size = pictureBox3.Size;
}
Points of Interest
Issues
- You don't have the functions/properties that you would with a standard
checkbox
- If you stretch out the
checkbox
(picturebox
), the quality will change for more obvious reasons
Other
Note that even though you don't have the functions/properties as a standard checkbox
, you can still see if it's checked. In the source code, I wrote some code allowing the app to display a messagebox telling you if it's checked or not.
Future Ideas
- It would be great if someone could make this into a DLL so that you could drag and drop from the toolbox in Visual Studio.
History
- 6/10/2011: Article creation date