2024年6月11日发(作者:)

C#仿QQ自动隐藏窗体

C#WinForm仿qq窗体拖到windows窗体边上时,自动隐藏C#WinForm。代码:

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

StopRectTimer = new

();

+= new EventHandler(timer1_Tick);

al = 50;

d = true;

t = true;

();

}

private void timer1_Tick(object sender, EventArgs e)

{

if (ns(on))

{

switch (nhor)

{

case :

on = new Point(on.X, 0);

break;

case :

on = new Point(0, on.Y);

break;

case :

on = new Point( -

, on.Y);

break;

case :

on = new Point(on.X,

- );

break;

}

}

else

{

switch (nhor)

{

case :

on = new Point(on.X, ( - 8) * (-1));

break;

case :

on = new Point((-1) * ( - 8), on.Y);

break;

case :

on = new Point( - 8,

on.Y);

break;

case :

on = new Point(on.X,

( - 8));

break;

}

}

}

internal AnchorStyles StopAanhor = ;

private void mStopAnhor()

{

if ( <= 0 && <= 0)

{

StopAanhor = ;

}

else if ( <= 0)

{

StopAanhor = ;

}

else if ( <= 0)

{

StopAanhor = ;

}

else if ( >= - )

{

StopAanhor = ;

}

else if ( >= - )

{

StopAanhor = ;

}

else

{

StopAanhor = ;

}

}

private void hide_LocationChanged(object sender, EventArgs e)

{

nhor();

}

}

在WinForm中添加Load事件给Form1_Load,添加LocationChanged事件给

hide_LocationChanged。

原理:主要是用Timer控件,在实时判断当前窗口的位置,如果在windows窗口的边上时,

修改窗口的位置。当窗口隐藏后,实时判断鼠标的位置,如果在窗口附件,窗口显示。