用c#实现类似qq的界面顶端停靠

aloyise 2009-07-30 10:38:59
小弟想做个这样功能的界面

看了几个帖子

说如此即可
class Win32API
{
[DllImport("user32.dll")]
public static extern bool PtInRect(ref Rectangle r, Point p);
}


private void timer1_Tick(object sender, EventArgs e)
{
System.Drawing.Point pp = new Point(Cursor.Position.X, Cursor.Position.Y);//获取鼠标在屏幕的坐标点
Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);//存储当前窗体在屏幕的所在区域
if ((this.Top < 0) && Win32API.PtInRect(ref Rects, pp))//当鼠标在当前窗体内,并且窗体的Top属性小于0
this.Top = 0; //设置窗体的Top属性为0,就是将窗口上边沿紧靠顶部
else if (this.Top > -5 && this.Top < 5 && !(Win32API.PtInRect(ref Rects, pp)))//当窗体的上边框与屏幕的顶端的距离小于5时
this.Top = 5 - this.Height;//将QQ窗体隐藏到屏幕的顶端



}

但是并为实现功能,小弟苦求,哭求
...全文
226 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fallen_Devil 2011-05-21
  • 打赏
  • 举报
回复
mark
logxing 2009-08-02
  • 打赏
  • 举报
回复
调用时前面还得加一句
int height = this.Height;

另外d316432574d,能不能加个动画效果,像QQ那样的。
logxing 2009-08-02
  • 打赏
  • 举报
回复
LS很帅。
另外.net平台别再想着用winapi了,不和谐啊。
liuxibei1987 2009-08-02
  • 打赏
  • 举报
回复
mark
nixiang12 2009-08-02
  • 打赏
  • 举报
回复
试试看 能不能用嘿嘿
logxing 2009-08-02
  • 打赏
  • 举报
回复
就好比你非插入汇编代码段来实现不使用汇编代码也能实现的功能一样。
代码不自然。
这涉及到好的定义。如果好的定义就是能运行,那就没什么值得讨论的了。
我觉得好的代码应该逻辑简洁,自然一致。
aloyise 2009-08-02
  • 打赏
  • 举报
回复
ls winapi 有啥不好么
d316432574d 2009-08-01
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aptech.UI;
using System.IO;
using MyWindowExecutablePrograms.Function;
using System.Drawing.Imaging;
using System.Data.SqlClient;

public class FormAutoDock
{
public static void SideHideOrShow(Form DockableForm, ref int DockFormHeight, Timer _dockTimer)
{
if (DockableForm.WindowState != FormWindowState.Minimized)
{
_dockTimer.Interval = 100;
if (Cursor.Position.X > DockableForm.Left - 1 && Cursor.Position.X < DockableForm.Right && Cursor.Position.Y > DockableForm.Top - 1 && Cursor.Position.Y < DockableForm.Bottom)
{
if (DockableForm.Top <= 0 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
{
DockableForm.Top = 0;
}
else if (DockableForm.Left <= 0)
{
DockableForm.Left = 0;
}
else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width)
{
DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width;
}
else
{
if (DockFormHeight > 0)
{
DockableForm.Height = DockFormHeight;
DockFormHeight = 0;
}
}
}
else
{
if (DockFormHeight < 1)
{
DockFormHeight = DockableForm.Height;
}
if (DockableForm.Top <= 4 && DockableForm.Left > 5 && DockableForm.Left < Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width)
{
DockableForm.Top = 3 - DockableForm.Height;
if (DockableForm.Left <= 4)
{
DockableForm.Left = -5;
}
else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - DockableForm.Width + 5;
}
}
else if (DockableForm.Left <= 4)
{
DockableForm.Left = 3 - DockableForm.Width;
}
else if (DockableForm.Left + DockableForm.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
DockableForm.Left = Screen.PrimaryScreen.WorkingArea.Width - 3;
}
_dockTimer.Interval = 100;
}
}
}

}

上面这个是类 类名叫FormAutoDock
在要用的窗体 拉一个Timer 设置好时间100就OK了 Enabled = true
在Tick事件里面调用这个类


FormAutoDock.SideHideOrShow(this, ref height, timer1);


OK的了 看那么多人需要才发的!
aloyise 2009-08-01
  • 打赏
  • 举报
回复
弟兄们,就我那个就可以了,能实现顶端停靠,我只是timer没打开。enable是false 我改成true就可以了,太爽了
qshurufa 2009-07-31
  • 打赏
  • 举报
回复
关注,帮顶!!
玖伍叁柒 2009-07-31
  • 打赏
  • 举报
回复
mark

关注中
VistaKobe 2009-07-31
  • 打赏
  • 举报
回复
关注高人解答!
nixiang12 2009-07-31
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zaiduxinling 的回复:]
引用 2 楼 forandever 的回复:
用过一个叫做 TaskForm.ocx 的控件,你搜索一下,可以免费使用的。

呵呵…就它了。
[/Quote]

在那里下载啊 没找到啊.
让爱延续 2009-07-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 forandever 的回复:]
用过一个叫做 TaskForm.ocx 的控件,你搜索一下,可以免费使用的。
[/Quote]
呵呵…就它了。
virus7581 2009-07-30
  • 打赏
  • 举报
回复
same
nixiang12 2009-07-30
  • 打赏
  • 举报
回复
关注 我也找这个好久了
forandever 2009-07-30
  • 打赏
  • 举报
回复
用过一个叫做 TaskForm.ocx 的控件,你搜索一下,可以免费使用的。
xiaogangqq123456 2009-07-30
  • 打赏
  • 举报
回复
关注!!!

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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