首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WinForm怎样做按钮的凸起和凹下效果vs2005(C#)解决思路

2012-01-24 
WinForm怎样做按钮的凸起和凹下效果vs2005(C#)WinForm怎样做按钮的凸起和凹下效果vs2005(C#)[解决办法]先

WinForm怎样做按钮的凸起和凹下效果vs2005(C#)
WinForm怎样做按钮的凸起和凹下效果vs2005(C#)

[解决办法]
先画好两个图分别是突起和按下效果的,放在你的项目中,然后在按钮的Mouseover事件或者Click时间里添加button.image="图片路径"。。
[解决办法]
定制一个吧。。
[解决办法]
比如我在项目的资源文件“Resource1.resx”里添加了两幅图片Image1和Image2,分别是按钮凸起和凹下的效果。
开始把按钮的Image属性值设为Image1,
button1.Image=global::button.Resource1.Image1;
然后再这个按钮的Mousehover事件里这样写:
private void button1_MouseHover(object sender, EventArgs e)
{
this.button1.Image = global::button.Resource.Image2;

}
[解决办法]
MouseHover
MouseDown
MouseLeave
事件都用上,就OK了……
[解决办法]
有一投机取巧的方法,用CheckBox来做Button。

效果请参考下面的代码,可直接编译运行:

C# code
// Form1.cs// compile with csc /t:winexe Form1.csusing System;using System.Drawing;using System.Windows.Forms;public class Form1 : Form{    public Form1()    {        CheckBox checkBox1 = new CheckBox();        Button button1 = new Button();        checkBox1.Text = "cancel";        checkBox1.Location = new Point(60, 80);        checkBox1.Appearance = Appearance.Button;               //<-------        checkBox1.CheckState = CheckState.Checked;        checkBox1.Size = new Size(80, 25);        checkBox1.TextAlign = ContentAlignment.MiddleCenter;                button1.Text = "ok";        button1.Location = new Point(60,120);        button1.Size = checkBox1.Size;        this.Controls.Add(checkBox1);        this.Controls.Add(button1);    }    static void Main()    {        Application.Run(new Form1());    }} 

热点排行