473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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

Jul 21 '05 #1
2 2215
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

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(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

.

Jul 21 '05 #3

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

Similar topics

1
5014
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.
4
3866
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.
5
6672
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...
20
5110
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...
3
3529
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.
3
5669
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...
17
4754
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
1
3660
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...
4
10759
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
1142
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
0
8822
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
9528
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
9359
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9310
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,...
0
9236
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
6792
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
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
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...
3
2206
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.