Click here to Skip to main content
Licence CPOL
First Posted 12 Jun 2011
Views 2,614
Downloads 63
Bookmarked 0 times

OSX Style Checkboxes in C#

By | 12 Jun 2011 | Article
Mac OSX Style Checkbox
OSX Checkbox

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

shelby67

Student
none
United States United States

Member



Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNot an article... PinmvpDave Kreskowiak4:08 12 Jun '11  
GeneralUm... PinmemberRavi Bhavnani4:00 12 Jun '11  
GeneralThis must be a joke PinmemberJefis3:30 12 Jun '11  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 12 Jun 2011
Article Copyright 2011 by shelby67
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid