在windform中,怎么设置无边框窗体自动上卷? 因为窗体设置了成了无边框, 即是将窗体的属性FormBorderStyle设置成了None,现在我是想当鼠标拖动窗体的时候,当拖动到屏幕上方边缘的时候,鼠标走开,窗体会缩上去,也就是隐藏了,就是 达到QQ的那种效果,请问大虾们应该如何实现这个功能? 最好能给出完整的代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/xiaowei0705/archive/2011/06/24/2089169.html 这是刚才改的一段代码,有什么不明白的问我。public partial class Form1 : Form { private AnchorStyles anchor = AnchorStyles.None; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Interval = 50; timer1.Enabled = true; TopMost = true; timer1.Start(); } private void mStopAnhor() { if (Top <= 0 && Left <= 0) { anchor = AnchorStyles.None; } else if (Top <= 0) { anchor = AnchorStyles.Top; } else if (Left <= 0) { anchor = AnchorStyles.Left; } else if (Left >= Screen.PrimaryScreen.Bounds.Width - Width) { anchor = AnchorStyles.Right; } else if (Top >= Screen.PrimaryScreen.Bounds.Height - Height) { anchor = AnchorStyles.Bottom; } else { anchor = AnchorStyles.None; } } private void Form1_LocationChanged(object sender, EventArgs e) { mStopAnhor(); } private void timer1_Tick(object sender, EventArgs e) { if (Bounds.Contains(Cursor.Position)) { switch (anchor) { case AnchorStyles.Top: Location = new Point(Location.X, 0); break; case AnchorStyles.Left: Location = new Point(0, Location.Y); break; case AnchorStyles.Right: Location = new Point(Screen.PrimaryScreen.Bounds.Width - Width, Location.Y); break; case AnchorStyles.Bottom: Location = new Point(Location.X, Screen.PrimaryScreen.Bounds.Height - Height); break; default: break; } } else { switch (anchor) { case AnchorStyles.Top: Location = new Point(Location.X, (Height - 8) * (-1)); break; case AnchorStyles.Left: Location = new Point((-1) * (Width - 8), Location.Y); break; case AnchorStyles.Right: Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, Location.Y); break; case AnchorStyles.Bottom: Location = new Point(Location.X, (Screen.PrimaryScreen.Bounds.Height - 8)); break; default: break; } } } } [Quote=引用 5 楼 llftc 的回复:]这是刚才改的一段代码,有什么不明白的问我。大神,谢啦。问题解决了,太犀利了,大神,能够留下你的QQ吗? 以后有不懂的可以请教你了。 Javascript 怎么调用CS中查到数据,并且怎么实现循环? 两个textbox,一个输入数字,一个输出阶乘的结果,button1 click事件怎么写 为将对象引用设置到对象实例??? 做个Table编辑器???? 我的安装问题 正则表达式完成字符替代??? Process.GetProcesses()的异常问题 如何做逻辑或判断? 为何我VS.net无法编写web程序。 如何解析pop3邮件的内容?最好能有源码参考一下 请问这是怎么个意思啊 ? DevExpress 如何才能让设计时控件也显示中文的.
public partial class Form1 : Form
{
private AnchorStyles anchor = AnchorStyles.None;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 50;
timer1.Enabled = true;
TopMost = true;
timer1.Start();
} private void mStopAnhor()
{
if (Top <= 0 && Left <= 0)
{
anchor = AnchorStyles.None;
}
else if (Top <= 0)
{
anchor = AnchorStyles.Top;
}
else if (Left <= 0)
{
anchor = AnchorStyles.Left;
}
else if (Left >= Screen.PrimaryScreen.Bounds.Width - Width)
{
anchor = AnchorStyles.Right;
}
else if (Top >= Screen.PrimaryScreen.Bounds.Height - Height)
{
anchor = AnchorStyles.Bottom;
}
else
{
anchor = AnchorStyles.None;
}
} private void Form1_LocationChanged(object sender, EventArgs e)
{
mStopAnhor();
} private void timer1_Tick(object sender, EventArgs e)
{
if (Bounds.Contains(Cursor.Position))
{
switch (anchor)
{
case AnchorStyles.Top:
Location = new Point(Location.X, 0);
break;
case AnchorStyles.Left:
Location = new Point(0, Location.Y);
break;
case AnchorStyles.Right:
Location = new Point(Screen.PrimaryScreen.Bounds.Width - Width, Location.Y);
break;
case AnchorStyles.Bottom:
Location = new Point(Location.X, Screen.PrimaryScreen.Bounds.Height - Height);
break;
default:
break;
}
}
else
{
switch (anchor)
{
case AnchorStyles.Top:
Location = new Point(Location.X, (Height - 8) * (-1));
break;
case AnchorStyles.Left:
Location = new Point((-1) * (Width - 8), Location.Y);
break;
case AnchorStyles.Right:
Location = new Point(Screen.PrimaryScreen.Bounds.Width - 8, Location.Y);
break;
case AnchorStyles.Bottom:
Location = new Point(Location.X, (Screen.PrimaryScreen.Bounds.Height - 8));
break;
default:
break;
}
}
}
}