当前位置: 移动技术网 > IT编程>开发语言>c# > c# 实现窗体拖到屏幕边缘自动隐藏

c# 实现窗体拖到屏幕边缘自动隐藏

2019年07月18日  | 移动技术网IT编程  | 我要评论
以下给出源代码: (注:hide为窗体名称)
复制代码 代码如下:

private void hide_load(object sender, eventargs e)
{
system.windows.forms.timer stoprecttimer = new system.windows.forms.timer();
stoprecttimer.tick += new eventhandler(timer1_tick);
stoprecttimer.interval = 100;
stoprecttimer.enabled = true;
}
private void timer1_tick(object sender, eventargs e)
{
if (this.bounds.contains(cursor.position))
{
switch (this.stopaanhor)
{
case anchorstyles.top:
this.location = new point(this.location.x, 0);
break;
case anchorstyles.left:
this.location = new point(0, this.location.y);
break;
case anchorstyles.right:
this.location = new point(screen.primaryscreen.bounds.width - this.width, this.location.y);
break;
}
}
else
{
switch (this.stopaanhor)
{
case anchorstyles.top:
this.location = new point(this.location.x, (this.height - 2) * (-1));
break;
case anchorstyles.left:
this.location = new point((-1) * (this.width - 2), this.location.y);
break;
case anchorstyles.right:
this.location = new point(screen.primaryscreen.bounds.width - 2, this.location.y);
break;
}
}
}
internal anchorstyles stopaanhor = anchorstyles.none;
private void mstopanhor()
{
if (this.top <= 0)
{
stopaanhor = anchorstyles.top;
}
else if (this.left <= 0)
{
stopaanhor = anchorstyles.left;
}
else if (this.left >= screen.primaryscreen.bounds.width - this.width)
{
stopaanhor = anchorstyles.right;
}
else
{
stopaanhor = anchorstyles.none;
}
}
private void hide_locationchanged(object sender, eventargs e)
{
this.mstopanhor();
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网