如何防止闪烁(双缓冲无助) [英] How to Prevent Flicker (Double-buffering not helping)

查看:73
本文介绍了如何防止闪烁(双缓冲无助)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是昨天发布的一篇关于屏蔽鼠标的信息。


我实施的解决方案 - 来自Herfried - 在整个用户控件上放置一个透明的

窗口,然后使用各种鼠标

事件,允许用户拖动控件而无需点击任何内容/>
到下面控件的按钮和下拉列表。一切都很好

好​​。


然而,当我启用和禁用

功能时,我得到一个难看的闪烁。 br />

我只是通过使透明窗口

可见或不可见来更改拖动启用功能。在任何一种情况下,当可见状态变为
时,我得到一个闪烁的控件下面我无法摆脱

of。我已尝试为表单和用户控件启用双缓冲

但它没有任何区别。奇怪的是,TrackBar

控制的问题非常糟糕,但其他控件难以察觉。


任何人都可以建议任何其他技巧来制作我的表格和控制

无闪烁?


TIA


Charles

解决方案

Charles,

我实施的解决方案 - 来自Herfried - 在整个用户控件上放置一个透明的窗口,然后使用各种鼠标
事件来允许用户拖动控制没有任何点击进入下面控件的按钮和下拉菜单。一切都很好

然而,当我启用和禁用
功能时,我得到一个难看的闪烁。

我改变拖动启用仅通过使透明窗口可见或不可见来实现。在任何一种情况下,当可见状态发生变化时,我得到一个闪烁的控件下面,我无法摆脱
。我已尝试为表单和用户控件启用双缓冲,但它没有任何区别。奇怪的是,TrackBar
控件的问题非常糟糕,但其他控件几乎察觉不到。




我实际上不会隐藏放在其他

控件。相反,我会处理''MouseUp''和''MouseDown''事件

并相应地移动透明控件后面的控件。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>

我刚尝试了这个,它似乎工作正常。

它可能是一种不同的拖拽方法,但它快速而简单。


我使用MenuItem(EditMenu)在设计和运行模式之间切换。

我从另一个名为

TransControl的线程中添加了透明控件。 br />
将此代码添加到表单中:


\\\

Const WM_NCLBUTTONDOWN As Integer =& HA1

Const HT_CAPTION As Integer =& H2


Private Sub TransControl_MouseDown(ByVal sender As Object,_

ByVal e As MouseEventArgs)Handles TransControl.MouseDown


如果Me.Controls.GetChildInde x(TransControl)<> 0然后返回


昏暗的孩子作为控制


每个c作为控制在我。控制

如果c .Bounds.Contains(eX,eY)那么

如果不是c是我而且也不是c是TransControl那么

孩子= c

结束如果

结束如果

下一页


如果孩子什么都没有那么返回


TransControl .Capture = False

WndProc(Message.Create(Child.Handle,WM_NCLBUTTONDO WN,_

IntPtr.op_Explicit(HT_CAPTION),IntPtr.Zero))

TransControl.BringToFront()

End Sub


Private Sub EditMenu_Click(ByVal sender As Object,ByVal e As EventArgs)_

处理EditMenu.Click


如果Me.Controls.GetChildIndex(TransControl)= 0那么

TransControl.SendToBack()

否则

TransControl.BringToFront()

结束如果


结束次级

///


-

Mick Doherty
http://dotnetrix.co.uk/nothing.html

" Charles Law" < BL *** @ nowhere.com>在留言中写道

新闻:Ol ************** @ TK2MSFTNGP12.phx.gbl ...

这实际上是一个关注从昨天关于屏蔽鼠标点击用户控件的帖子开始。

我实施的解决方案 - 来自Herfried - 在整个用户控件上放置了一个透明的窗口然后,它使用各种鼠标
事件,允许用户拖动控件,无需任何点击,直到下面控件的按钮和下拉菜单。一切都很好

然而,当我启用和禁用
功能时,我得到一个难看的闪烁。

我改变拖动启用仅通过使透明窗口可见或不可见来实现。在任何一种情况下,当可见状态发生变化时,我得到一个闪烁的控件下面,我无法摆脱
。我已尝试为表单和用户
控件启用双缓冲,但它没有任何区别。奇怪的是,
TrackBar控件的问题非常糟糕,但其他控件却难以察觉。

任何人都可以提出任何其他技巧来制作我的表格和控件
无闪烁吗? br />
TIA

Charles



---

外发邮件经过认证无病毒。

由AVG反病毒系统检查( http:// www。 grisoft.com)

版本:6.0.701 /病毒数据库:458 - 发布日期:07/06/2004


我也试过更改z顺序,但这对我来说并没有改善。

另外,透明窗口的位不包含在

控件中即使在运行模式下也可以拖动用户控件。


对我来说更糟糕的是我有一个带子窗口的MDI应用程序。

这个子窗口包含我的用户控件,它本身由用户组成

控制。基类是实现透明窗口的基类,

并且还包括轨迹栏控件。当我在设计和

运行模式之间切换时,只有轨迹栏控件消失,然后再重新绘制
。这是非常明显的。就好像轨道条控件有特定的东西




Charles

Mick Doherty

< EX *********** @ AND.REMOVE.SQUAREBRACKETS。[mdaudi100#ntlworld.com]>写在

消息新闻:eG ************** @ tk2msftngp13.phx.gbl ...

我刚试了这个它似乎工作正常。
它可能是一个不同的拖动方法,但它很快和
简单。
我使用MenuItem(EditMenu)在设计和运行之间切换模式。
我从另一个名为
TransControl的线程中添加了透明控件。
将此代码添加到您的表单中:

\\\
Const WM_NCLBUTTONDOWN As Integer =& HA1
Const HT_CAPTION As Integer =& H2
私有Sub TransControl_MouseDown(ByVal发送者为对象,_
ByVal e As MouseEventArgs)处理TransControl.MouseDown

如果Me.Controls.GetChildIndex(TransControl)<> 0然后返回

昏暗的孩子作为控制

对于每个c作为控制在我。控制
如果c.Bounds.Contains(eX,eY)然后
如果不是c是我而且也不是c是TransControl然后
孩子= c
结束如果
结束如果


如果孩子什么都没有那么返回

TransControl.Capture = False
WndProc(Message.Create(Child.Handle,WM_NCLBUTTONDO WN,_
IntPtr.op_Explicit(HT_CAPTION),IntPtr.Zero))



私人子EditMenu_Click(ByVal发件人作为对象,ByVal e As EventArgs)_
处理EditMenu.Click

如果Me.Controls.GetChildIndex(TransControl)= 0那么
TransControl.SendToBack()
否则
TransControl.BringToFront()
结束如果
结束子
///

- Mick Doherty
http://dotnetrix.co.uk/nothing.html

" Charles Law" < BL *** @ nowhere.com>在消息中写道
新闻:Ol ************** @ TK2MSFTNGP12.phx.gbl ...

这实际上是昨天的后续行动'关于在用户控件中屏蔽鼠标点击的帖子。

我实施的解决方案 - 来自Herfried - 在整个用户控件上放置一个透明的窗口,然后使用各种鼠标
事件,允许用户在没有任何点击的情况下拖动控件,直到下面控件的按钮和下拉菜单。一切都很好

然而,当我启用和禁用
功能时,我得到一个难看的闪烁。

我改变拖动启用仅通过使透明窗口可见或不可见来实现。在任何一种情况下,当可见状态改变时,我得到闪烁的控件下面,我无法得到
摆脱。我已经尝试为表单和用户启用双缓冲


control

但它没有区别。奇怪的是,这个问题对于


TrackBar

控制非常糟糕,但对于其他控件却难以察觉。

任何人都可以建议任何其他制作技巧我的表格和控件无闪烁?

TIA

Charles



--- 由AVG反病毒系统检查( http: //www.grisoft.com)
版本:6.0.701 /病毒数据库:458 - 发布日期:07/06/2004



This is actually a follow on from yesterday''s post about masking mouse
clicks in a user control.

The solution I have implemented - from Herfried - places a transparent
window over the entire user control, which then uses the various mouse
events to allow the user to drag the control without any clicks going
through to the buttons and dropdowns on the control below. All well and
good.

However, I am getting an unsightly flicker when I enable and disable the
feature.

I change the drag enable feature simply by making the transparent window
either visible or not visible. In either case, when the visible state is
changed, I get a flicker of the controls underneath that I cannot get rid
of. I have tried enabling double-buffering for the form and the user control
but it makes no difference. Oddly, the problem is very bad for the TrackBar
control, but imperceptible for other controls.

Can anyone suggest any other techniques for making my form and control
flicker free?

TIA

Charles

解决方案

Charles,

* "Charles Law" <bl***@nowhere.com> scripsit:

The solution I have implemented - from Herfried - places a transparent
window over the entire user control, which then uses the various mouse
events to allow the user to drag the control without any clicks going
through to the buttons and dropdowns on the control below. All well and
good.

However, I am getting an unsightly flicker when I enable and disable the
feature.

I change the drag enable feature simply by making the transparent window
either visible or not visible. In either case, when the visible state is
changed, I get a flicker of the controls underneath that I cannot get rid
of. I have tried enabling double-buffering for the form and the user control
but it makes no difference. Oddly, the problem is very bad for the TrackBar
control, but imperceptible for other controls.



I would not actually hide the control that is placed over the other
controls. Instead, I would handle the ''MouseUp'' and ''MouseDown'' events
and move the controls behind the transparent control accordingly.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


I just tried this out and it seems to work OK.
It''s probably a different drag method to yours but it was quick and simple.

I use a MenuItem (EditMenu) to switch between Design and Run Mode.
I added the Transparent Control from the other thread which I named
TransControl.
Add this code to your form:

\\\
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const HT_CAPTION As Integer = &H2

Private Sub TransControl_MouseDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles TransControl.MouseDown

If Me.Controls.GetChildIndex(TransControl) <> 0 Then Return

Dim Child As Control

For Each c As Control In Me.Controls
If c.Bounds.Contains(e.X, e.Y) Then
If Not c Is Me AndAlso Not c Is TransControl Then
Child = c
End If
End If
Next

If Child Is Nothing Then Return

TransControl.Capture = False
WndProc(Message.Create(Child.Handle,WM_NCLBUTTONDO WN, _
IntPtr.op_Explicit(HT_CAPTION), IntPtr.Zero))
TransControl.BringToFront()

End Sub

Private Sub EditMenu_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles EditMenu.Click

If Me.Controls.GetChildIndex(TransControl) = 0 Then
TransControl.SendToBack()
Else
TransControl.BringToFront()
End If

End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Charles Law" <bl***@nowhere.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...

This is actually a follow on from yesterday''s post about masking mouse
clicks in a user control.

The solution I have implemented - from Herfried - places a transparent
window over the entire user control, which then uses the various mouse
events to allow the user to drag the control without any clicks going
through to the buttons and dropdowns on the control below. All well and
good.

However, I am getting an unsightly flicker when I enable and disable the
feature.

I change the drag enable feature simply by making the transparent window
either visible or not visible. In either case, when the visible state is
changed, I get a flicker of the controls underneath that I cannot get rid
of. I have tried enabling double-buffering for the form and the user control but it makes no difference. Oddly, the problem is very bad for the TrackBar control, but imperceptible for other controls.

Can anyone suggest any other techniques for making my form and control
flicker free?

TIA

Charles


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004


I also tried changing the z-order, but this did not improve things for me.
In addition, the bits of the transparent window that are not covered by
controls allows the user control to be dragged even in run mode.

What may make it worse for me is that I have an MDI app with a child window.
This child window contains my user control which is itself made up of user
controls. The base class is the one that implements the transparent window,
and also includes the track bar control. When I switch between design and
run mode it is only the track bar control that disappears and is then
redrawn. It is very noticeable. It is as if there is something specific with
the track bar control.

Charles
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eG**************@tk2msftngp13.phx.gbl...

I just tried this out and it seems to work OK.
It''s probably a different drag method to yours but it was quick and simple.
I use a MenuItem (EditMenu) to switch between Design and Run Mode.
I added the Transparent Control from the other thread which I named
TransControl.
Add this code to your form:

\\\
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const HT_CAPTION As Integer = &H2

Private Sub TransControl_MouseDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles TransControl.MouseDown

If Me.Controls.GetChildIndex(TransControl) <> 0 Then Return

Dim Child As Control

For Each c As Control In Me.Controls
If c.Bounds.Contains(e.X, e.Y) Then
If Not c Is Me AndAlso Not c Is TransControl Then
Child = c
End If
End If
Next

If Child Is Nothing Then Return

TransControl.Capture = False
WndProc(Message.Create(Child.Handle,WM_NCLBUTTONDO WN, _
IntPtr.op_Explicit(HT_CAPTION), IntPtr.Zero))
TransControl.BringToFront()

End Sub

Private Sub EditMenu_Click(ByVal sender As Object, ByVal e As EventArgs) _
Handles EditMenu.Click

If Me.Controls.GetChildIndex(TransControl) = 0 Then
TransControl.SendToBack()
Else
TransControl.BringToFront()
End If

End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Charles Law" <bl***@nowhere.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...

This is actually a follow on from yesterday''s post about masking mouse
clicks in a user control.

The solution I have implemented - from Herfried - places a transparent
window over the entire user control, which then uses the various mouse
events to allow the user to drag the control without any clicks going
through to the buttons and dropdowns on the control below. All well and
good.

However, I am getting an unsightly flicker when I enable and disable the
feature.

I change the drag enable feature simply by making the transparent window
either visible or not visible. In either case, when the visible state is
changed, I get a flicker of the controls underneath that I cannot get rid of. I have tried enabling double-buffering for the form and the user


control

but it makes no difference. Oddly, the problem is very bad for the


TrackBar

control, but imperceptible for other controls.

Can anyone suggest any other techniques for making my form and control
flicker free?

TIA

Charles


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004



这篇关于如何防止闪烁(双缓冲无助)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆