点击按钮,在电脑右下端弹出提示框,鼠标不离开,提示框不消失。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;


namespace 弹出消息框
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form fmessage;
private void btnStart_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
fmessage = new Form();
fmessage.Width = 350;
fmessage.Height = 280;
fmessage.MaximizeBox = false;
fmessage.MinimizeBox = false;
fmessage.Text = "武侠奇缘";
fmessage.BackgroundImage = Image.FromFile(@"F:\netstudy\work\画图和控件练习\弹出消息框\Resources\2.png");
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - fmessage.Width, Screen.PrimaryScreen.WorkingArea.Height);
fmessage.PointToScreen(p);
fmessage.Location = p;
fmessage.Show();
for (int i = 0; i <= fmessage.Height; i++)
{
fmessage.Location = new Point(p.X, p.Y - i);
Thread.Sleep(10);
}
}
private void timer1_Tick_1(object sender, EventArgs e)
{
Thread.Sleep(2000);
int flag = 1;
while (flag==1)
{
while (true)
{
if ((System.Windows.Forms.Control.MousePosition.X >= fmessage.Location.X) && (System.Windows.Forms.Control.MousePosition.Y >= fmessage.Location.Y))
{

}
else
{
break;
}
}
timer1.Enabled = false;
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - fmessage.Width, Screen.PrimaryScreen.WorkingArea.Height);
fmessage.PointToScreen(p);//
for (int i = fmessage.Height; i >= 0; i--)
{
//当鼠标又指上去的时候
if ((System.Windows.Forms.Control.MousePosition.X >= fmessage.Location.X) && (System.Windows.Forms.Control.MousePosition.Y >= fmessage.Location.Y))
{
fmessage.Location = new Point(p.X, p.Y);
flag = 1;
break;
}
flag = 0;
fmessage.Location = new Point(p.X, p.Y - i);
Thread.Sleep(10);
}
if (flag == 0)
{
break;
}
}
fmessage.Close();
}
}

}

实验结果截图:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值