473,849 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Prevent Flicker (Double-buffering not helping)

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
Nov 20 '05 #1
20 5131
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/>
Nov 20 '05 #2
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_NCLBUTTONDOW N As Integer = &HA1
Const HT_CAPTION As Integer = &H2

Private Sub TransControl_Mo useDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles TransControl.Mo useDown

If Me.Controls.Get ChildIndex(Tran sControl) <> 0 Then Return

Dim Child As Control

For Each c As Control In Me.Controls
If c.Bounds.Contai ns(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.Ca pture = False
WndProc(Message .Create(Child.H andle,WM_NCLBUT TONDOWN, _
IntPtr.op_Expli cit(HT_CAPTION) , IntPtr.Zero))
TransControl.Br ingToFront()

End Sub

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

If Me.Controls.Get ChildIndex(Tran sControl) = 0 Then
TransControl.Se ndToBack()
Else
TransControl.Br ingToFront()
End If

End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Charles Law" <bl***@nowhere. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.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
Nov 20 '05 #3
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.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:eG******** ******@tk2msftn gp13.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_NCLBUTTONDOW N As Integer = &HA1
Const HT_CAPTION As Integer = &H2

Private Sub TransControl_Mo useDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles TransControl.Mo useDown

If Me.Controls.Get ChildIndex(Tran sControl) <> 0 Then Return

Dim Child As Control

For Each c As Control In Me.Controls
If c.Bounds.Contai ns(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.Ca pture = False
WndProc(Message .Create(Child.H andle,WM_NCLBUT TONDOWN, _
IntPtr.op_Expli cit(HT_CAPTION) , IntPtr.Zero))
TransControl.Br ingToFront()

End Sub

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

If Me.Controls.Get ChildIndex(Tran sControl) = 0 Then
TransControl.Se ndToBack()
Else
TransControl.Br ingToFront()
End If

End Sub
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Charles Law" <bl***@nowhere. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.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

Nov 20 '05 #4
> 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.
I'm not sure I quite follow you. Are you saying that you would have the
controls behind the transparent control always? If that is the case, how
would you pass the mouse events to the controls behind when the control is
not draggable, i.e not in design mode?

Charles
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2l******** ****@uni-berlin.de... 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/>

Nov 20 '05 #5
* "Charles Law" <bl***@nowhere. com> scripsit:
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.


I'm not sure I quite follow you. Are you saying that you would have the
controls behind the transparent control always? If that is the case, how
would you pass the mouse events to the controls behind when the control is
not draggable, i.e not in design mode?


You would have to implement the dragging yourself and check what control
is under the mouse pointer based on position and Z-order. Sure, that's
very complicated and I assume that there are easier solutions...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
Hmm. The easier solution I had in mind was making the transparent control
invisible when not in design mode. Then, it's just one line.

Assuming, for the moment, that I don't go down the route of writing all this
extra code, can you think why only the track bar control should disappear,
whilst checkboxes, labels and a progress bar are rock steady?

Charles
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2l******** ****@uni-berlin.de...
* "Charles Law" <bl***@nowhere. com> scripsit:
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.


I'm not sure I quite follow you. Are you saying that you would have the
controls behind the transparent control always? If that is the case, how
would you pass the mouse events to the controls behind when the control is not draggable, i.e not in design mode?


You would have to implement the dragging yourself and check what control
is under the mouse pointer based on position and Z-order. Sure, that's
very complicated and I assume that there are easier solutions...

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

Nov 20 '05 #7
* "Charles Law" <bl***@nowhere. com> scripsit:
Hmm. The easier solution I had in mind was making the transparent control
invisible when not in design mode. Then, it's just one line.
Mhm... But then, the controls can receive focus, which is not the case
for VS.NET's Windows Forms designer.
Assuming, for the moment, that I don't go down the route of writing all this
extra code, can you think why only the track bar control should disappear,
whilst checkboxes, labels and a progress bar are rock steady?


Sorry, I don't understand this sentence... My English is too bad.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
> Mhm... But then, the controls can receive focus, which is not the case
for VS.NET's Windows Forms designer.
Ah, yes, but that is what I want to happen. When in 'design mode' the user
can drag one of my user controls around the form and position it at will.
When they come out of design mode, the user control should behave just like
a regular control, with buttons pressing and performing actions and
dropdowns dropping down for selection.
Assuming, for the moment, that I don't go down the route of writing all this extra code, can you think why only the track bar control should disappear, whilst checkboxes, labels and a progress bar are rock steady?
I was just asking why the track bar might behave differently. It is the only
control that I use that has this flicker problem. Actually, it is more than
just a flicker, because the control is erased and then redrawn.

Charles
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2l******** ****@uni-berlin.de... * "Charles Law" <bl***@nowhere. com> scripsit:
Hmm. The easier solution I had in mind was making the transparent

control invisible when not in design mode. Then, it's just one line.


Mhm... But then, the controls can receive focus, which is not the case
for VS.NET's Windows Forms designer.
Assuming, for the moment, that I don't go down the route of writing all this extra code, can you think why only the track bar control should disappear, whilst checkboxes, labels and a progress bar are rock steady?


Sorry, I don't understand this sentence... My English is too bad.

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

Nov 20 '05 #9
Charles,
In your many posts on your project, did anyone ever refer you to this
article on creating a Windows Forms Designer?

I'm just wondering if the article (or sample code) has any insights that may
help you in your endeavors...

http://www.windowsforms.net/default....mID=13&mid=142

Along the same lines I wonder if the Sharp Develop source would give you any
ideas.

http://www.icsharpcode.net/OpenSource/SD/

As it sounds like you are creating a Designer of sorts...

Hope this helps
Jay

"Charles Law" <bl***@nowhere. com> wrote in message
news:Ol******** ******@TK2MSFTN GP12.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

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2223
by: Abhishek | last post by:
My objective is quite simple. I want to display a JPG image and then on it overlay a polygon. This polygon can be moved by a user. The even is trapped on the mouse down event of the control. I can make the polygon move but the screen flickers because I call invalidate() on the mouse down event. I did do offscreen buffering but there is still flashing in the screen. Let me explain what I am doing. in the pain even handler of the control I...
1
11065
by: Alessandro Fragnani | last post by:
Hi, I would like to know how to avoid flicker while adding controls to a panel. I couldn´t find any kind of "BeginUpdate/EndUpdate" on it. Thanks in advance Alessandro
3
3536
by: Per Dunberg | last post by:
Hi all, I have to develop a "skinned" application and I have a problem with the graphics. When a form is loaded and displayed there's aways a flicker where all the controls are located on the form. It seems like the controls erase the background and this cause a flicker everytime a form i loaded. When I hide and show forms that are already loaded there's no flicker, it's just when the form is loaded the first time.
5
10617
by: Charles Law | last post by:
Some of the eagle-eyed amongst you will spot this as a direct follow on from my earlier post about critical timing in .NET. I want to use a ListView to display my output (instead of the sluggish RichTextBox), but it flickers madly when I update it. There have been numerous posts about this, but I have found no solution. Enabling double-buffering does not seem to help, so has anyone any idea how it can be done? TIA
1
3425
by: Jeff Williams | last post by:
I have a form with several tabs and I want to dynamically change the opacity of it while shown. Is there a way to stop the form updating on screen until all controls have change opacity then allow the form to display. Lookings for something like this.SuspendUpdate then
4
10763
by: Frank Rizzo | last post by:
Hello, I inherited a large Winforms project that is suffering from excessive flicker when switching between portions of the application. I've noticed that most parts of the application (user controls and forms) have DoubleBuffered set to true. In addition to that, in the constructor of every form and user control, there is this line: SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11005
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4139
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.