以下给出源代码: (注: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();
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
深入了解c# 匿名类型
一、什么叫做匿名类? 匿名类就是没有名字的类。匿名类不能被引用,只能再创建的时候用new语句来声明。二、匿名类的优势以及应用场景; 1、匿名类型提供了一种方...
[阅读全文]
-
-
C# 实现俄罗斯方块(附源码)
概述俄罗斯方块(tetris)是一款由俄罗斯人阿列克谢·帕基特诺夫发明的休闲游戏,帕基特诺夫爱玩拼图,从拼图游戏里得到灵感,设计出了俄罗斯方块。由于上手简单、老...
[阅读全文]
-
浅析c# 接口
接口:是指定一组函数成员而不是实现他们的引用类型。所以只能类喝啊结构来实现接口,在结成该接口的类里面必须要实现接口的所有方法接口的特点:继承于接口的类,必须要实...
[阅读全文]
-
c# 接口使用实例
用接口实现一个简单的物件的入库,出库如定义一个物流类接口,包含物件所属快递公司名称属性,物件单号属性及信息显示方法。通过物件出库类信息和物件入库类信息继承该接口...
[阅读全文]
-
-
-
-
-
快速了解c# 常量
常量是固定值,程序执行期间不会改变。常量可以是任何基本数据类型,比如整数常量、浮点常量、字符常量或者字符串常量,还有枚举常量。常量可以被当作常规的变量,只是它们...
[阅读全文]
网友评论