472,354 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Problem with PictureBox flickering.

Hello,

I'm working on a project that basically draws lines onto a PictureBox control. Now I'm using a Timer with an interval of 100 to draw the information. Now my code looks something like this:

Private Sub Draw()
m_pPictBox.Refresh()
' Draw etc...
End Sub
Private Sub m_pTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_pTimer.Tick
Draw()
End Sub
Now, everytime the Draw function gets called, I see the drawing "flicker" (ie flash on/off) in the PictureBox. I've tried using m_pPictBoxGraphics.Clear(Color.Gray) (or any other color) but it still causes it to flicker.
Any suggestions would be most helpful. Thank you.
Ryan
Nov 21 '05 #1
8 10665
"Ryan Chavez" <rt******@hotmail.com> schrieb
Hello,

I'm working on a project that basically draws lines onto a PictureBox
control. Now I'm using a Timer with an interval of 100 to draw the
information. Now my code looks something like this:

Private Sub Draw()
m_pPictBox.Refresh()
' Draw etc...
Why do you call Refresh before drawing?
End Sub
Private Sub m_pTimer_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_pTimer.Tick
Draw()
End Sub
Now, everytime the Draw function gets called, I see the drawing
"flicker" (ie flash on/off) in the PictureBox. I've tried using
m_pPictBoxGraphics.Clear(Color.Gray) (or any other color) but it
still causes it to flicker. Any suggestions would be most helpful.
Thank you.
Ryan


You might consider inheriting from the picturebox and call the SetStyle
method to enable double buffering:

In the constructor:

setstyle( _
ControlStyles.AllPaintingInWmPaint _
Or ControlStyles.DoubleBuffer _
Or ControlStyles.UserPaint, _
True _
)

I'd also suggest to override the OnPaintBackground and OnPaint methods and
paint everything there. You can leave OnPaintBackground empty and also clear
the background in OnPaint, so you have all the rendering in one place. In
the Form hosting the new control, you can call it's Invalidate method
whenever you want it to be repainted.

Armin

Nov 21 '05 #2
Thank you Armin. I created a class that inherited the PictureBox and did
like you suggested with the SetStyle in the constructure and it worked
really good. I still get a small amout of flicker but not nearly as much as
before. I also don't use m_pPictureBox.Refresh() anymore since I went back
to using m_pPictBoxGraphics.Clear(m_pPictBoxGraphics.BackCo lor). I'm gonna
look into overridding the OnPaintBackground and OnPaint events to see if
that will help. Thanks again.

Ryan
"Armin Zingler" <az*******@freenet.de> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...
"Ryan Chavez" <rt******@hotmail.com> schrieb
Hello,

I'm working on a project that basically draws lines onto a PictureBox
control. Now I'm using a Timer with an interval of 100 to draw the
information. Now my code looks something like this:

Private Sub Draw()
m_pPictBox.Refresh()
' Draw etc...


Why do you call Refresh before drawing?
End Sub
Private Sub m_pTimer_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_pTimer.Tick
Draw()
End Sub
Now, everytime the Draw function gets called, I see the drawing
"flicker" (ie flash on/off) in the PictureBox. I've tried using
m_pPictBoxGraphics.Clear(Color.Gray) (or any other color) but it
still causes it to flicker. Any suggestions would be most helpful.
Thank you.
Ryan


You might consider inheriting from the picturebox and call the SetStyle
method to enable double buffering:

In the constructor:

setstyle( _
ControlStyles.AllPaintingInWmPaint _
Or ControlStyles.DoubleBuffer _
Or ControlStyles.UserPaint, _
True _
)

I'd also suggest to override the OnPaintBackground and OnPaint methods and
paint everything there. You can leave OnPaintBackground empty and also
clear the background in OnPaint, so you have all the rendering in one
place. In the Form hosting the new control, you can call it's Invalidate
method whenever you want it to be repainted.

Armin

Nov 21 '05 #3
Hello,

I am facing a similar problem. I have a MDI form with another form as the
MDI Client. The client has a Panel control on which I draw stuff. I noticed
that there is a lot of flikering when I draw anything.

As per the earlier suggestion I added the following code to the MDI client's
code. However the problem still persists.
///
InitializeComponent()

Me.SetStyle(ControlStyles.DoubleBuffer Or _
ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.UserPaint Or _
ControlStyles.Opaque, True)

Me.UpdateStyles()

\\\

Any suggestions??

TIA
Nov 21 '05 #4
"Sarika" <Sa****@discussions.microsoft.com> schrieb
Hello,

I am facing a similar problem. I have a MDI form with another form as
the MDI Client. The client has a Panel control on which I draw
stuff. I noticed that there is a lot of flikering when I draw
anything.

As per the earlier suggestion I added the following code to the MDI
client's code. However the problem still persists.
///
InitializeComponent()

Me.SetStyle(ControlStyles.DoubleBuffer Or _
ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.UserPaint Or _
ControlStyles.Opaque, True)

Me.UpdateStyles()

\\\

Any suggestions??

TIA

If the panel is flickering the style of the panel must be changed. As
SetStyle is protected, it has to be done in a control inherited from Panel.
Armin

Nov 21 '05 #5
Hi Armin,

Well I tried that too. I tried the SetStyle method for the Panel instead of
the form and it did not work.

However I am not sure I understand you when you said
"As SetStyle is protected, it has to be done in a control inherited from
Panel"

I don't have any control that inherits from the Panel. The Panel acts as the
drawing area and a container for a textbox
Nov 21 '05 #6
Armin,

In my earlier post I mentioned that I tred the double buffering w/ the
Panel. Well I actually just tried with the form and did not realise it
because of the syntax was for the form and hence it did not raise a flag.

Anyways. So regarding your suggestion....

I need to create a class which inherits the Panel class and set the
properties there. I then use this class to create a Panel on which I will do
my drawing.

Did I get you right?

Just an observation

I draw lines, text, boxes and also drag and drop some images from my
treeview control. I noticed that drawing the Lines causes NO flicker whereas
drawing any other object or moving it causes some flicker.

Maybe you will be able to shed some light on this.

Thanks again for your reponse.
Nov 21 '05 #7
"Sarika" <Sa****@discussions.microsoft.com> schrieb
Armin,

In my earlier post I mentioned that I tred the double buffering w/
the Panel. Well I actually just tried with the form and did not
realise it because of the syntax was for the form and hence it did
not raise a flag.

Anyways. So regarding your suggestion....

I need to create a class which inherits the Panel class and set the
properties there. I then use this class to create a Panel on which I
will do
my drawing.

Did I get you right?
I don't understand "I then use this class...". The class *is* a panel.
Replace the current panel by an instance of the new class. Unfortunatelly,
the IDE doesn't add it automatically to the toolbox like it does with
Usercontrols.
Just an observation

I draw lines, text, boxes and also drag and drop some images from my
treeview control. I noticed that drawing the Lines causes NO flicker
whereas
drawing any other object or moving it causes some flicker.

Maybe you will be able to shed some light on this.

Thanks again for your reponse.

Do you draw inside the Panel's OnPaint method?

Armin

Nov 21 '05 #8
Okay I think I understand what you are saying with the inheritance.

I call a DrawAll method inside the Panel's Paint event. This DrawAll method
in turn calls the ClassPaint method of each of the classes whose objects need
to be drawn on the screen.
Nov 21 '05 #9

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

Similar topics

2
by: John Lee | last post by:
Hi, I have a windows application that uses the listview to display about 50 items in detailed view - 4 columns. The first column is static and other columns will be updated in 100-1000ms - it...
2
by: John Lee | last post by:
Thanks Jay for your response. I tried your code and it still flickering a lot. To demonstrate it, you can grab a listview, create 3 columns - name, value, timestamp, in form_load event to add 50...
5
by: n00b | last post by:
I have some forms with maybe around 30 controls on each and anytime I load these forms different parts of it start flickering though not all of them at once and not the same ones everytime. the...
2
by: sasifiqbal | last post by:
Hi, One of my developers are facing an interesting problem regarding UserControl invalidation. The problem is: We have two forms in our application. Form A does nothing except loading of...
6
by: Mark Thompson | last post by:
I have a problem with my Visual Basic .NET 2003 application which I have so far been unable to resolve. I am trying to get an OpenGL control that I have created working properly as a control on...
1
by: James | last post by:
Hi all, I have made a derived Listview which can accept the controls as items in it. Controls that we are using are Buttons in each row and implemented Grouping with the help of controls(label on...
3
by: b747_440 | last post by:
Hello Newsgroup, I try to resize and move a picturebox. However, after each operation the picture box is being redrawn. This causes flickering. Is it possible to suppress the first redraw and draw...
2
by: Eren AYKIN | last post by:
Hello Everybody, I'm not very experienced with DFT and FFTW library and I want to ask your opinion about the results I get. My aim is to determine if the sample input sequence is flickering with...
7
by: MasterMax1313 | last post by:
I'm trying to make a grid of picture box controls, which I do via code. Each of these boxes has a mouseclick, mousedown, mouseup, and mouseenter event. The mouseclick event is simple enough and works...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.