Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i found this buttons (psd file) and i want to make them work in C# form. ( like adroid or ios settings - on and off buttons ).

http://up.pnu-club.com/di-TY35.jpg[^]

http://up.pnu-club.com/di-IRHJ.jpg[^]

how to make these buttons work in C# form ?
Posted
Updated 25-Dec-15 4:31am
v3
Comments
Zoltán Zörgő 25-Dec-15 10:29am    
What has this to do with SQL???
brandon1999 25-Dec-15 10:30am    
oh, sorry - that was my mistake. :D

1 solution

I just threw this together.
Check the code - it's converted from VB.

(Try it using 2 of your top row buttons cut into approx. 100x35 pixels)

C#
#region "Imports"using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
#endregion

[ToolboxBitmap(typeof(Button)), ToolboxItem(true), DesignTimeVisible(true)]
public class OnOffButtons : System.Windows.Forms.Button
{

	#region "Private members"
	private Image m_OnImage = My.Resources.OnImage;
	private Image m_OffImage = My.Resources.OffImage;
		#endregion
	private bool m_ON;

	public OnOffButtons() : base()
	{
		this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
		base.BackgroundImageLayout = ImageLayout.Zoom;
                this.Text="";
		SetImage();
	}

	public OnOffButtons(Image onImage, Image offImage) : base()
	{
		this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
		base.BackgroundImageLayout = ImageLayout.Zoom;
		m_OffImage = offImage;
		m_OnImage = onImage;
                this.Text="";
		SetImage();
	}

	[RefreshProperties(RefreshProperties.Repaint)]
	public Image OffImage {
		get { return this.m_OffImage; }
		set { this.m_OffImage = value; }
	}

	[RefreshProperties(RefreshProperties.Repaint)]
	public Image OnImage {
		get { return this.m_OnImage; }
		set { this.m_OnImage = value; }
	}

	private void SetImage()
	{
		if (m_ON) {
			this.BackgroundImage = m_OnImage;
		} else {
			this.BackgroundImage = m_OffImage;
		}
		Refresh();
	}

	protected override void OnClick(System.EventArgs e)
	{
		m_ON = !m_ON;
		SetImage();
		base.OnClick(e);
	}
}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================
 
Share this answer
 
v2
Comments
brandon1999 25-Dec-15 13:07pm    
thanks

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900