C# 窗体吸附 RT:类似于 QQ的 吸附功能 就是把窗体 拖到右上角 快到的时候 自动吸附到 右上角 ,鼠标在拖动窗体的时候又改回来··咋搞····· 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做一个判断if (this.Left < xxx) this.Left = 0; 为你的窗体设置属性,例如public Point 吸附之前窗体的最后坐标;然后再你的执行“吸附”功能的代码的第一行采集窗体左上角坐标和设置这个属性,“改回来”这个部分使用它。“吸附”,就是在触发拖动事件(鼠标移动事件,同时当前鼠标一直按下没有抬起来)并且没有设置这个属性(这个属性为null)时检测一下左边、右边、下边、上边。而“改回来”,就是这个事件中当这个属性不为null时的状态。 放一个timer1控件,interval设置成1秒//实现接近屏幕窗体边源吸附 private void timer1_Tick(object sender, EventArgs e) { if (this.WindowState != System.Windows.Forms.FormWindowState.Minimized) { if (Cursor.Position.X > this.Left && Cursor.Position.X < this.Right && Cursor.Position.Y > this.Top && Cursor.Position.Y < this.Bottom) { if (this.Top < 0) { this.Top = -5; this.Show(); } else if (this.Left < 0) { this.Left = -5; this.Show(); } else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width) { this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5; this.Show(); } } else { if (this.Top <= 4) { this.Top = 5 - this.Height; if (this.Left <= 4) { this.Left = -5; } else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4) { this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5; } } else if (this.Left <= 4) { this.Left = 5 - this.Width; } else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4) { this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5; } } } } C# winform开发 誰可以给个FTP上传例子 显示上传进度的 高分求DataGridViewCheckBoxCell状态问题. 100求解!~~急.. 请问如何控制线程启动、暂停、停止。 C#求大神帮忙看看程序 如何将一个项目的全局把握好 请教一个算法问题 如何使用对象数组? 1.0升级1.1代来的问题Request[]出错 怎样获得服务器的时间并用农历显示出来? 问题如下图,哪种写法好? c# mdi窗体
if (this.Left < xxx) this.Left = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (this.WindowState != System.Windows.Forms.FormWindowState.Minimized)
{
if (Cursor.Position.X > this.Left && Cursor.Position.X < this.Right && Cursor.Position.Y > this.Top && Cursor.Position.Y < this.Bottom)
{
if (this.Top < 0)
{
this.Top = -5;
this.Show();
}
else if (this.Left < 0)
{
this.Left = -5;
this.Show();
}
else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width)
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5;
this.Show();
}
}
else
{
if (this.Top <= 4)
{
this.Top = 5 - this.Height;
if (this.Left <= 4)
{
this.Left = -5;
}
else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width + 5;
}
}
else if (this.Left <= 4)
{
this.Left = 5 - this.Width;
}
else if (this.Left + this.Width >= Screen.PrimaryScreen.WorkingArea.Width - 4)
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
}
}
} }