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;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
if (WindowState != FormWindowState.Minimized)
{
int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width; //屏幕宽度
int ScreenRight = Screen.PrimaryScreen.WorkingArea.Right; //屏幕高度
int MouseX = Control.MousePosition.X; //鼠标X位置
int MouseY = Control.MousePosition.Y;//鼠标垂直位置
if (this.Left < 0 && this.Top < 0)
{
this.Left = 0;
this.Top = 1;
}
if (this.Left >= ScreenWidth - this.Right && this.Top < 0) //如果自己的左边是否在屏幕的边缘
{
this.Left = ScreenWidth;
this.Top = 0;
}
if (this.Top < 0 && MouseX > this.Left && MouseX < this.Left + this.Width && MouseY < 3)
{
this.Top = 0;
}
if (this.Top <= 0 && this.Left > 0 && this.Left < ScreenWidth - this.Width)
{
if (MouseX < this.Left || MouseX > this.Left + this.Width || MouseY > this.Top + this.Right)
{
this.Top = 3 - this.Right;
}
}
if (this.Left < 0 && MouseY > this.Top && MouseY < this.Top + this.Width && MouseX < 3)
{
this.Left = 0;
}
if (this.Left <= 0 && this.Top > 0 && this.Top < ScreenRight - this.Right)
{
if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX > this.Width)
{
this.Left = 3 - this.Width;
}
}
if (this.Left >= ScreenWidth - this.Width && this.Top > 0 && this.Top < ScreenRight - this.Width)
{
if (MouseY < this.Top || MouseY > this.Top + this.Right || MouseX < ScreenWidth - this.Width)
{
this.Left = ScreenWidth - 3;
}
}
if (this.Left > ScreenWidth - 5) //判断自己的左边是否隐藏了
{
if (MouseX > ScreenWidth - 5) //如果隐藏了 判断鼠标是不在屏幕的边缘
{
this.Left = ScreenWidth - this.Width;
}
}
}
}
}
}
|