日期:2014-05-18  浏览次数:22515 次

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.cs

using 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());
    }
}