472,358 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

flicker problem

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 have the
following approach. please tell me if nothing can be done or i am going
wrong somewhere

private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs
paintg)
{
Graphics gxOff; //create an Offscreen graphics
if (m_bmpOffscreen == null) //Bitmap for doublebuffering, create if not
created
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
//m_bmpOffscreen is a private member of the class
gxOff = Graphics.FromImage(m_bmpOffscreen);//Attach image
gxOff.Clear(this.BackColor);
gxOff.DrawImage(m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pixel); // here
I draw my JPG image which fills the cliend area of the control
//this image does not change except when one goes to the file menu and
opens another.
gxOff.DrawPolygon(blackPen, (Point[])rose.GenerateRoseCurvePts());
//this is where I draw the polygon. This is the part that changes with each
mouse down and mouse move.
paintg.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(paintg);
}
Rest on the mouse move
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging) // if the polygon is being dragged
{
//compute new set of point
panel1.Invalidate(); //Now this causes the paint even to be called
for everymovement of the mouse.
}
}

Where am I going wrong? Is there are a better alternative. can I control the
rate at which refreshing is taking place? the image in the background needs
not be repainted again and again but since I am drawing the polygon on it
and to move the polygon to a new position I need to do it. also how can I
control the rate at which refreshing takes place so that there is no
flicker?
Thanks in anticipation
Abhishek

Jul 21 '05 #1
2 2088
Hi,

The panel is flickering because you are invalidating the whole
panel. Only invalidate what you want redrawn.

Ken
-------------------
"Abhishek" <ga*****@rpi.edu> wrote in message
news:uQ**************@TK2MSFTNGP11.phx.gbl...
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 have
the
following approach. please tell me if nothing can be done or i am going
wrong somewhere

private void panel1_Paint(object sender,
System.Windows.Forms.PaintEventArgs
paintg)
{
Graphics gxOff; //create an Offscreen graphics
if (m_bmpOffscreen == null) //Bitmap for doublebuffering, create if not
created
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
//m_bmpOffscreen is a private member of the class
gxOff = Graphics.FromImage(m_bmpOffscreen);//Attach image
gxOff.Clear(this.BackColor);
gxOff.DrawImage(m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pixel); //
here
I draw my JPG image which fills the cliend area of the control
//this image does not change except when one goes to the file menu and
opens another.
gxOff.DrawPolygon(blackPen, (Point[])rose.GenerateRoseCurvePts());
//this is where I draw the polygon. This is the part that changes with
each
mouse down and mouse move.
paintg.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(paintg);
}
Rest on the mouse move
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (dragging) // if the polygon is being dragged
{
//compute new set of point
panel1.Invalidate(); //Now this causes the paint even to be called
for everymovement of the mouse.
}
}

Where am I going wrong? Is there are a better alternative. can I control
the
rate at which refreshing is taking place? the image in the background
needs
not be repainted again and again but since I am drawing the polygon on it
and to move the polygon to a new position I need to do it. also how can I
control the rate at which refreshing takes place so that there is no
flicker?
Thanks in anticipation
Abhishek

Jul 21 '05 #2
Hi,

As well as Ken's suggested fix, there is another thing
you can do that may improve the flickering.

Create a new control that derives from the build in Panel
control. In the constructor for the control, use the
SetStyle method to enable double buffering. Double
buffering makes the image draw off screen before being
copied onto the screen.

The syntax (c#) is something like this:
SetStyle(ControlStyle.DoubleBuffering, true);

HTH

Eddie de Bear
MCSD
-----Original Message-----
My objective is quite simple. I want to display a JPG image and then on itoverlay a polygon. This polygon can be moved by a user. The even is trappedon the mouse down event of the control. I can make the polygon move but thescreen flickers because I call invalidate() on the mouse down event. I diddo offscreen buffering but there is still flashing in the screen. Let meexplain what I am doing. in the pain even handler of the control I have thefollowing approach. please tell me if nothing can be done or i am goingwrong somewhere

private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgspaintg)
{
Graphics gxOff; //create an Offscreen graphics
if (m_bmpOffscreen == null) //Bitmap for doublebuffering, create if notcreated
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);//m_bmpOffscreen is a private member of the class
gxOff = Graphics.FromImage(m_bmpOffscreen);//Attach image gxOff.Clear(this.BackColor);
gxOff.DrawImage(m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pixel); // hereI draw my JPG image which fills the cliend area of the control //this image does not change except when one goes to the file menu andopens another.
gxOff.DrawPolygon(blackPen, (Point[]) rose.GenerateRoseCurvePts());//this is where I draw the polygon. This is the part that changes with eachmouse down and mouse move.
paintg.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(paintg);
}
Rest on the mouse move
private void panel1_MouseMove(object sender, MouseEventArgs e){
if (dragging) // if the polygon is being dragged
{
//compute new set of point
panel1.Invalidate(); //Now this causes the paint even to be calledfor everymovement of the mouse.
}
}

Where am I going wrong? Is there are a better alternative. can I control therate at which refreshing is taking place? the image in the background needsnot be repainted again and again but since I am drawing the polygon on itand to move the polygon to a new position I need to do it. also how can Icontrol the rate at which refreshing takes place so that there is noflicker?
Thanks in anticipation
Abhishek

.

Jul 21 '05 #3

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

Similar topics

1
by: Michael | last post by:
Here is my problem: I have a MDI application and when I load my child forms I get alot of flicker. I have tried to implement double buffering : Public Sub New() MyBase.New() 'This call is...
4
by: Marek Mänd | last post by:
This seems an IE issue only: 4253 bytes testcase: http://www.hot.ee/idaliiga/testcases/ieselect/bnlinkingselectinmsie.htm Can one have 1) a mouseover/mouseout element on TBODY 2) change in...
5
by: Ian Stiles | last post by:
I have tried everything under the sun to get rid of horrible flashing and flickering that occurs on a CSharp form when the form hosts a TreeView or WebBrowser control and then you resize the form....
20
by: Charles Law | last post by:
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...
3
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...
3
by: seamlyne | last post by:
The first method I ever used for multiple state buttons was to create a graphic for each button for each state: AboutUs_on, AbooutUs_over, AboutUs_out, etc. That works great when there are just a...
17
by: pigeonrandle | last post by:
Hi, I have seen loads of different ways to do this, but the all seem to yield the same result - text that doesn't flicker when it's moving too slowly! Does anyone know 'the best way' to make text...
1
by: Wayne | last post by:
I've noticed some screen flicker when using Access 2003 under Vista and I'm curious as to whether this is a bug or peculiar to my machine. In design view, if I make changes to a form and then...
4
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...
0
by: Rainer Queck | last post by:
Hello NG, I had/have a bad flicker Problem with my Application. On starting some applications, while my app was running, the whole Display started to flicker. Even the desktop Icons! Looking...
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: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
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...
1
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
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
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.