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(ob ject sender, System.Windows. Forms.PaintEven tArgs
paintg)
{
Graphics gxOff; //create an Offscreen graphics
if (m_bmpOffscreen == null) //Bitmap for doublebuffering , create if not
created
m_bmpOffscreen = new Bitmap(ClientSi ze.Width, ClientSize.Heig ht);
//m_bmpOffscreen is a private member of the class
gxOff = Graphics.FromIm age(m_bmpOffscr een);//Attach image
gxOff.Clear(thi s.BackColor);
gxOff.DrawImage (m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pi xel); // 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.DrawPolyg on(blackPen, (Point[])rose.GenerateR oseCurvePts());
//this is where I draw the polygon. This is the part that changes with each
mouse down and mouse move.
paintg.Graphics .DrawImage(m_bm pOffscreen, 0, 0);
base.OnPaint(pa intg);
}
Rest on the mouse move
private void panel1_MouseMov e(object sender, MouseEventArgs e)
{
if (dragging) // if the polygon is being dragged
{
//compute new set of point
panel1.Invalida te(); //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 2219
Hi,
The panel is flickering because you are invalidating the whole
panel. Only invalidate what you want redrawn.
Ken
-------------------
"Abhishek" <ga*****@rpi.ed u> wrote in message
news:uQ******** ******@TK2MSFTN GP11.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(ob ject sender, System.Windows. Forms.PaintEven tArgs paintg) { Graphics gxOff; //create an Offscreen graphics if (m_bmpOffscreen == null) //Bitmap for doublebuffering , create if not created m_bmpOffscreen = new Bitmap(ClientSi ze.Width, ClientSize.Heig ht); //m_bmpOffscreen is a private member of the class gxOff = Graphics.FromIm age(m_bmpOffscr een);//Attach image gxOff.Clear(thi s.BackColor); gxOff.DrawImage (m_bmpOrg, 0, 0, rectBmpOrg, GraphicsUnit.Pi xel); // 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.DrawPolyg on(blackPen, (Point[])rose.GenerateR oseCurvePts()); //this is where I draw the polygon. This is the part that changes with each mouse down and mouse move. paintg.Graphics .DrawImage(m_bm pOffscreen, 0, 0); base.OnPaint(pa intg); } Rest on the mouse move private void panel1_MouseMov e(object sender, MouseEventArgs e) { if (dragging) // if the polygon is being dragged { //compute new set of point panel1.Invalida te(); //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(Contro lStyle.DoubleBu ffering, 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(ob ject sender,
System.Windows. Forms.PaintEven tArgspaintg) { Graphics gxOff; //create an Offscreen graphics if (m_bmpOffscreen == null) //Bitmap for
doublebuffering , create if notcreated m_bmpOffscreen = new Bitmap(ClientSi ze.Width,
ClientSize.Heig ht);//m_bmpOffscreen is a private member of the class gxOff = Graphics.FromIm age(m_bmpOffscr een);//Attach
image gxOff.Clear(thi s.BackColor); gxOff.DrawImage (m_bmpOrg, 0, 0, rectBmpOrg,
GraphicsUnit.Pi xel); // 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.DrawPolyg on(blackPen, (Point[])
rose.GenerateRo seCurvePts());//this is where I draw the polygon. This is the part
that changes with eachmouse down and mouse move. paintg.Graphics .DrawImage(m_bm pOffscreen, 0, 0); base.OnPaint(pa intg); } Rest on the mouse move private void panel1_MouseMov e(object sender,
MouseEventArgs e){ if (dragging) // if the polygon is being dragged { //compute new set of point panel1.Invalida te(); //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 required by the Windows Form Designer.
|
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 thoise event handler background colors
3) have a specified heighted SELECT element, that doesnt flicker
when the event handlers are get called.
|
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.
Here is what I've tried so far:
1. Turning off CS_VREDRAW and CS_HREDRAW in both the parent form and a
subclass of the control via the "override CreateParams" property
(these values were already off).
2. Setting various styles and handling...
|
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 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...
|
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.
| |
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 few buttons.
I'm creating interfaces now with many more buttons than "just a few".
I solved the maintenance problem by having generic button images, one
for each state, and having them be background images for text
containers, DIVs in this...
|
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 scroll...
eg
Override OnPain and OnPaintBackground
Override WndProc
|
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 close the form, a
couple of seconds after I have OKed the save prompt the Database
Window that shows all my objects gives one flicker.
Once again, in design view if I change a property for a control in the
Properties box and then move the mouse...
|
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);
|
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 for help on this issue, I ran over a anser Linda Liu at :
http://groups.google.de/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/39e9f7d0b96b048f?hl=de
where I found the following (quick and dirty )solution to the flicker
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |