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 2 2169
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
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 . This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |