如何创建动画按钮? [英] how to Create Animated Button ?

查看:78
本文介绍了如何创建动画按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个按钮(psd文件),我想让它们以C#形式工作。 (如adroid或ios设置 - 开启和关闭按钮)。



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



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



如何让这些按钮以C#格式运行?

解决方案

我把它扔到了一起。

检查代码 - 它是从VB转换的。



(尝试使用2个顶行按钮切成约100x35像素)



   #regionImportsusing System; 
使用 System.Collections;
使用 System.Collections.Generic;
使用 System.Data;
使用 System.Diagnostics;
使用 System.Windows.Forms.Design;
使用 System.Windows.Forms;
使用 System.Drawing;
使用 System.ComponentModel;
使用 System.ComponentModel.Design;
#endregion

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

#region私有成员
私人图片m_OnImage = My.Resources.OnImage ;
private 图片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;
.Text = ;
SetImage();
}

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

[RefreshProperties(RefreshProperties.Repaint)]
public Image OffImage {
获取 {返回 .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();
}

受保护 覆盖 void OnClick(System.EventArgs e)
{
m_ON =!m_ON;
SetImage();
base .OnClick(e);
}
}

// ====== =================================================
// Telerik提供的服务(www.telerik.com)
// 由NRefactory提供的转换。
// Twitter:@telerik
// Facebook:facebook.com/telerik
// ==== ================================================== =


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 ?

解决方案

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)

#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
//=======================================================


这篇关于如何创建动画按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆