用C#语言编写一个简单程序,要求点击关闭的时候窗口慢慢消失然后自动关闭,求准确代码。

已经会用Timer控件使窗体慢慢变淡直到的消失,也会用If语句让窗体透明度为零时自动关闭。可是不明白怎么让右上角的关闭按钮触发以上事件,求代码。... 已经会用Timer控件使窗体慢慢变淡直到的消失,也会用If语句让窗体透明度为零时自动关闭。可是不明白怎么让右上角的关闭按钮触发以上事件,求代码。 展开
 我来答
匿名用户
2013-09-22
展开全部
#region 私有变量
private int heightMax, widthMax;//窗体的最大高度和宽度
public int StayTime = 1;//定时器时间间隔
#endregion #region 封装窗体高度宽度
public int HeightMax
{
set
{
heightMax = value;
}
get
{
return heightMax;
}
} public int WidthMax
{
set
{
widthMax = value;
}
get
{
return widthMax;
}
}
#endregion #region 窗体加载事件
public AttentionProgram()
{
InitializeComponent();
}
private void AttentionProgram_Load(object sender, EventArgs e)
{
#region 窗体弹出用到的数据
Screen[] screens = Screen.AllScreens;     //得到所有显示器 Screen screen = screens[0]; //得到显示器对象 this.Location = new Point(screen.WorkingArea.Width - this.Width, screen.WorkingArea.Height - this.Height);  //初始化当前的消息提示窗体的坐标位置 this.timer2.Interval = StayTime;  //初始化第二个计时器 与第一个计时器的时间间隔
#endregion }
#endregion #region 定时器事件
private void timer1_Tick(object sender, EventArgs e)
{
ScrollUp();
}
private void timer2_Tick(object sender, EventArgs e)
{
this.GetReleaseInfo();
this.timer2.Enabled = false;        //禁用第二计时器,启用第三计时器
this.timer3.Enabled = true;
}
private void timer3_Tick(object sender, EventArgs e)
{
ScrollDown();
}
#endregion #region 方法
public void ScrollShow()
{
this.Height = 0;     //初始化当前移动窗体的高度
this.Show();       //将其显示出来
this.timer1.Enabled = true; //开始调用第一个计时器 }
private void ScrollDown()
{
if (this.Height > 35)
{
this.Height = this.Height - 10;
this.Location = new Point(this.Location.X, this.Location.Y + 10);   //得到当前的坐标位置
}
else
{
this.timer3.Enabled = false;
this.Close();
}
}
private void ScrollUp()
{
if (this.Height < heightMax)  //判断当前的高度是不是小于最大高度,如果是的,就增加高度
{
this.Height = this.Height + 10; this.Location = new Point(this.Location.X, this.Location.Y - 10);  //设置当前窗体的坐标位置
}
else
{
this.timer1.Enabled = false;   //当前高度不小于最大高度时,就将计时器一禁用,启用计时器二 this.timer2.Enabled = true;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
MarsCode
2024-08-21 广告
编写代码需明确目标,如开发一个简单的程序,可先设计算法,再使用编程语言(如Python)构建逻辑。示例:```python# 打印“Hello, World!”print("Hello, World!")# 实现简单的加法运算def add... 点击进入详情页
本回答由MarsCode提供
匿名用户
2013-09-22
展开全部
在FormClosing里写e.Cancel = true;则关闭无效,当然还需要自己设个变量,去判断这次关闭是Timer里关闭的还是别的地方关闭的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式