WinForm怎样做按钮的凸起和凹下效果vs2005(C#) WinForm怎样做按钮的凸起和凹下效果vs2005(C#) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 FlatStyle属性设为Popup 不过只有当鼠标放在按钮上的时候才显示想要的效果 这是什么原因呀? 先画好两个图分别是突起和按下效果的,放在你的项目中,然后在按钮的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; } MouseHoverMouseDownMouseLeave事件都用上,就OK了…… 看过一本书上是这样模拟popup的 平时的时候paint就是画一个黑边白背景的rectangle 鼠标over的时候变成中间白背景 矩形是左边和上边用白色勾边 右边和下边用黑色勾边 就变成呢个popup的效果了 有一投机取巧的方法,用CheckBox来做Button。效果请参考下面的代码,可直接编译运行:// 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()); }} 问3句代码 当日结贴 c#开发环境 数据库死锁问题,请求解决。 在windows 7上可以用visual c#开发程序吗? 创建表语句 如何实现类似QQ那样的自动升级? 求教用8位的数字怎么表示颜色 WINDOWS7下如何屏蔽ctrl+alt+del键? 程序安装的部署问题 System.Management.dll引用问题 winform 添加了一个用户控件窗体,要怎样拖到其它窗体上面用啊?自定义的用户控件怎么用? SOS,VS2005里我连接不上资源文件
这是什么原因呀?
开始把按钮的Image属性值设为Image1,
button1.Image=global::button.Resource1.Image1;
然后再这个按钮的Mousehover事件里这样写:
private void button1_MouseHover(object sender, EventArgs e)
{
this.button1.Image = global::button.Resource.Image2;
}
MouseDown
MouseLeave
事件都用上,就OK了……
// 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());
}
}