分享一个小功能, 桌面工作区停靠代码. 附Demo下载地址.

lvyb057 2012-08-17 06:34:42
加精
原文地址
http://hi.baidu.com/windowssdk/item/c0dd1a0ad2b379d075cd3cf0
源码下载地址
http://www.everbox.com/f/2H5ya8hwKpPGxBTNSCg1zVWOY6

经常用PPLive看电影发现它的桌面停靠非常方便, 所以想给自己的程序加上这个个小功能.
之所以说"工作区"是因为类似Google Desktop工具的存在, 它会改变工作区域大小, PPLive是不知道工作区边界地, 有待改进.

动画演示太麻烦, 直接上代码吧.

/// <summary>
/// 鼠标坐标
/// </summary>
private Point PointMouse;
/// <summary>
/// 停靠范围
///
/// 用变量可以支持用户自定义修改属性.
/// </summary>
private int IntDockWidth = 15;

private void Controls_MouseDown( object sender, MouseEventArgs e ) {
PointMouse = new Point( -e.X, -e.Y );
Control c = ( Control )sender;
PointMouse.Offset( -c.Left, -c.Top );
}
private void Controls_MouseMove( object sender, MouseEventArgs e ) {
if ( e.Button == MouseButtons.Left ) {
Point mousePos = System.Windows.Forms.Control.MousePosition;
mousePos.Offset( PointMouse.X, PointMouse.Y );

//判断是否已经处于边缘
if ( ( mousePos.X - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.X ) <= IntDockWidth ) {
//左边
mousePos.X = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.X;
} else if ( ( System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - mousePos.X - this.Width ) <= IntDockWidth ) {
//右边
mousePos.X = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - this.Width;
}

if ( ( mousePos.Y - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Y ) <= IntDockWidth ) {
//上面
mousePos.Y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Y;
} else if ( ( System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - mousePos.Y - this.Height ) <= IntDockWidth ) {
//下边
mousePos.Y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - this.Height;
}
this.Location = mousePos;
}
}


订阅事件即可
...全文
877 41 打赏 收藏 转发到动态 举报
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
songjinxi123 2012-09-10
  • 打赏
  • 举报
回复
试了一下,发现窗口只有停靠功能,没有自动缩进去的功能。
songjinxi123 2012-09-10
  • 打赏
  • 举报
回复
这的确是一个很有用的功能啊。学习了。
lvyb058 2012-09-10
  • 打赏
  • 举报
回复
lvyb058 2012-08-27
  • 打赏
  • 举报
回复
lvyb058 2012-08-24
  • 打赏
  • 举报
回复
lvyb058 2012-08-24
  • 打赏
  • 举报
回复
猴头 2012-08-23
  • 打赏
  • 举报
回复
我记得有一个家伙前一段时间(一个月前还是两月前)分享过采用三个定时器的,可以在四个边自动隐藏的代码,我找不到了,看到的人 顺便把链接贴出来,谢谢
ljj3215 2012-08-23
  • 打赏
  • 举报
回复
很好,谢谢分享
lvyb058 2012-08-23
  • 打赏
  • 举报
回复
lipeng1750 2012-08-22
  • 打赏
  • 举报
回复
谢谢了
lvyb058 2012-08-22
  • 打赏
  • 举报
回复
lvyb058 2012-08-22
  • 打赏
  • 举报
回复
[Quote=引用 27 楼 的回复:]

多屏就废了。。
[/Quote]

多屏我没测试环境, 也不知道多屏的原理.
Conmajia 2012-08-22
  • 打赏
  • 举报
回复
多屏就废了。。
越过越咸 2012-08-21
  • 打赏
  • 举报
回复
每天回帖
ayun00 2012-08-21
  • 打赏
  • 举报
回复
我运行 怎么没有效果啊
lvyb058 2012-08-21
  • 打赏
  • 举报
回复
lvyb058 2012-08-20
  • 打赏
  • 举报
回复
猴头 2012-08-20
  • 打赏
  • 举报
回复
楼主,四个角呢??判断下
小班得瑞 2012-08-20
  • 打赏
  • 举报
回复
不错,谢谢
YHL27 2012-08-20
  • 打赏
  • 举报
回复
路过。。。
加载更多回复(19)

7,765

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧