C# 拖动窗口 一卡一卡的

flurrying 2009-03-06 04:56:40
拖动窗口 一卡一卡的

有没有不卡的拖动窗口方法呀!
...全文
826 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
flurrying 2009-03-07
  • 打赏
  • 举报
回复
我知道怎么回事了!
是因为Vista风格半透明时钟控件窗体
时钟一直在画图。所以特卡
jimolaixi 2009-03-06
  • 打赏
  • 举报
回复
ctrl.Left = pCtrlLastCoordinate.X + pCursorOffset.X;
ctrl.Top = pCtrlLastCoordinate.Y + pCursorOffset.Y;
实际上控件会移两次,还是使用ctrl.Location=new Point()好,不过谈不上优化。
会卡的有几个地方:
1. LocationChanged事件
2. Paint事件
3. 程序有没有正在执行什么
ztenv 2009-03-06
  • 打赏
  • 举报
回复
第三方控件?
flurrying 2009-03-06
  • 打赏
  • 举报
回复
这是拖动的类文件

帮忙优化一下


/////////////////////////////////////////////////////////类文件开始

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace CNPOPSOFT.Controls
{
/// <summary>
/// 类摘自(http://blog.csdn.net/dekko/archive/2007/09/24/1797903.aspx)
/// </summary>
public class ControlMoveResize
{
#region 私有成员
bool IsMoving = false;
Point pCtrlLastCoordinate = new Point(0, 0);
Point pCursorOffset = new Point(0, 0);
Point pCursorLastCoordinate = new Point(0, 0);
private Control ctrl = null;
private Timer tim = null;
private ScrollableControl Containe = null;
#endregion
#region 私有方法
/// <summary>
/// 在鼠标左键按下的状态记录鼠标当前的位置,以及被移动组件的当前位置
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MouseDown(object sender, MouseEventArgs e)
{
if (Containe == null)
{
return;
}
if (e.Button == MouseButtons.Left)
{
IsMoving = true;
pCtrlLastCoordinate.X = ctrl.Left;
pCtrlLastCoordinate.Y = ctrl.Top;
pCursorLastCoordinate.X = Cursor.Position.X;
pCursorLastCoordinate.Y = Cursor.Position.Y;
}
}
private void MouseMove(object sender, MouseEventArgs e)
{
if (Containe == null)
{
return;
}
if (e.Button == MouseButtons.Left)
{
if (this.IsMoving)
{
Point pCursor = new Point(Cursor.Position.X, Cursor.Position.Y);
pCursorOffset.X = pCursor.X - pCursorLastCoordinate.X;
pCursorOffset.Y = pCursor.Y - pCursorLastCoordinate.Y;
ctrl.Left = pCtrlLastCoordinate.X + pCursorOffset.X;
ctrl.Top = pCtrlLastCoordinate.Y + pCursorOffset.Y;
}
}
}
public static void TimerBegin(System.Windows.Forms.Timer timer)
{
timer.Start();
}

private void MouseUp(object sender, MouseEventArgs e)
{
if (Containe == null)
{
return;
}

if (this.IsMoving)
{
if (pCursorOffset.X == 0 && pCursorOffset.Y == 0)
{
return;
}
if ((pCtrlLastCoordinate.X + pCursorOffset.X + ctrl.Width) > 0)
{
ctrl.Left = pCtrlLastCoordinate.X + pCursorOffset.X;
}
else
{
ctrl.Left = 0;
}
if ((pCtrlLastCoordinate.Y + pCursorOffset.Y + ctrl.Height) > 0)
{
ctrl.Top = pCtrlLastCoordinate.Y + pCursorOffset.Y;
}
else
{
ctrl.Top = 0;
}
TimerBegin(tim);
pCursorOffset.X = 0;
pCursorOffset.Y = 0;
}
}
#endregion
#region 构造函数
/// <summary>
/// 获取被移动控件对象和容器对象
/// </summary>
/// <param name="c">被设置为可运行时移动的控件</param>
/// <param name="parentContain">可移动控件的容器</param>
public ControlMoveResize(Control c,Timer t,ScrollableControl parentContain)
{
ctrl = c;
tim = t;
this.Containe = parentContain;
ctrl.MouseDown += new MouseEventHandler(MouseDown);
ctrl.MouseMove += new MouseEventHandler(MouseMove);
ctrl.MouseUp += new MouseEventHandler(MouseUp);
}
#endregion
}
}
/////////////////////////////////////////////////////////类文件结束

ztenv 2009-03-06
  • 打赏
  • 举报
回复
Vista风格半透明时钟控件窗体

1、显卡的问题
2、如果是自己写的程序,估计每次拖动都计算了Form.Region,所以会卡;
flurrying 2009-03-06
  • 打赏
  • 举报
回复
我拖动的窗体是"Vista风格半透明时钟控件窗体"

一卡卡的,拖动一般窗体不卡
loworth 2009-03-06
  • 打赏
  • 举报
回复
装显卡驱动了么
ztenv 2009-03-06
  • 打赏
  • 举报
回复
和你进程的处理任务应该有关系,
flurrying 2009-03-06
  • 打赏
  • 举报
回复
WINFROM 的

111,126

社区成员

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

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

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