473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

GDI+ flicker isseue

i'm still a newbie and i really don't get it. i've read like 20-30 other threads on the forum but i can't make it work. This is the deal: a simple 2d drawing application, all the drawings are in a panel. i're read that something about Style must be set in the constructor.. wich contructor? Panel's? or Form? how to i override onPaintBackground? do i have to do another class that inherites Panel? in the new class constructor i must set Control Style? where should i put an instance of this new class? my old panel should be replaced by the instance of this new class?

Expand|Select|Wrap|Line Numbers
  1.         private void pnlDraw_MouseMove(object sender, MouseEventArgs e)
  2.         {
  3.             this.lblMouseMove.Text = "( " + e.X.ToString() + ", " + e.Y.ToString() + " )";
  4.             Graphics g = pnlDraw.CreateGraphics();
  5.  
  6.  
  7.  
  8.             if (activePencil && mouseDown)
  9.             {
  10.                 g.DrawLine(new Pen(System.Drawing.Color.Black, 3),start.X, start.Y, e.X, e.Y);
  11.                 start.X = e.X;
  12.                 start.Y = e.Y;
  13.             }
  14.  
  15.  
  16.             //temp figure 
  17.  
  18.             tempGP = new GraphicsPath();
  19.            if (mouseDown)
  20.             if (activeSquare)
  21.                 tempGP.AddRectangle(new Rectangle(start.X, start.Y, e.X - start.X, e.Y - start.Y));
  22.             else
  23.                 if (activeCircle)
  24.                     tempGP.AddEllipse(new Rectangle(start.X, start.Y, e.X - start.X, e.Y - start.Y));
  25.                 else
  26.                     if (activeLine)
  27.                         tempGP.AddLine(start.X,start.Y,e.X,e.Y);
  28.  
  29.  
  30.  
  31.  
  32.             g.DrawPath(Pens.Black, tempGP);
  33.             this.Refresh();
  34.  
  35.             if (gp != null) 
  36.                 if (gp.IsVisible(e.X, e.Y)) g.FillPath(Brushes.BlueViolet, gp);
  37.                 else g.FillPath(Brushes.White, gp);
  38.             this.Invalidate();
  39.  
  40.             //translate
  41.            // activeTranslate = false;
  42.  
  43.             if (mouseDown && activeTranslate)
  44.             {
  45.                 this.Cursor = Cursors.SizeAll;
  46.                 foreach (GraphicsPath gpi in allGraphicsPath)
  47.                     if (gpi.IsVisible(e.X, e.Y))
  48.                     {
  49.                         gp = gpi;
  50.                         break;
  51.                     }
  52.                 GraphicsPath gpPrevious = gp;
  53.  
  54.  
  55.                 Matrix translate = new Matrix(1, 0, 0, 1, 0, 0);
  56.                 translate.Translate(e.X - start.X, e.Y - start.Y);
  57.                 if (gp != null)
  58.                     if (gp.IsVisible(e.X, e.Y) && mouseDown && activeTranslate)
  59.                     {
  60.                         start.X = e.X;
  61.                         start.Y = e.Y;
  62.                         gp.Transform(translate);
  63.                         allGraphicsPath.Remove(gpPrevious);
  64.                         allGraphicsPath.Add(gp);
  65.                         this.pnlDraw.Refresh();
  66.                         gpPrevious = gp;
  67.                     }
  68.             }
  69.  
  70.             foreach (GraphicsPath gpi in allGraphicsPath)
  71.                 if (gpi != null)
  72.                 {
  73.                     if (activeTranslate)
  74.                         if (allGraphicsPath.Contains(gp))
  75.                         {
  76.                         }
  77.                     if (gpi.IsVisible(e.X, e.Y))
  78.                         g.FillPath(Brushes.BlueViolet, gpi);
  79.                     else
  80.                         g.FillPath(Brushes.White, gpi);
  81.                 }
  82.             this.Invalidate();
  83.  
  84.         }
  85.  
  86.  
  87.  
Wich Invalidate/Refresh should be deleted?

i hope you find you're answers for my questions


Thank you,
George
Apr 28 '07 #1
0 1182

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
3
by: Mike Kitchen | last post by:
I am writing an application in visual basic from a C# that I have already written. I am trying to convert the following line of code into VB, but I do not completely understand the help pages....
7
by: news | last post by:
This may be a stupid question, but if I don't ask I'll never know ;) Ok, here it goes.... I am writing an application that renders an image in one picturebox and a graph in another. The image...
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...
12
by: iwdu15 | last post by:
hi, i created a paint program for my c++ class using a global GraphicsPath variable. i the, in the onpaint method, draw the line the users draws with the mouse. simple. the only problem is that...
7
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be...
1
by: Daniel | last post by:
Hi I had an app i write on DirectX that will nearly always run in a windowed situation. It could also have many instances running at a time and as such to keep the cpu usage down i had a frame...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
Hi Folks, I'm not sure where this post belongs since I'm using managed vc.net, but the issue is around GDI BitBlt. Here is a summary of the problem: - I am trying to copy a bitmap of my main...
7
by: =?Utf-8?B?U2ltb24gVGFtbWFu?= | last post by:
I was trying to double buffer a control while drawing on CE devices. The code below is compiled under the compact framework but you can also run it on the desktop and it produces the same problem....
7
by: =?Utf-8?B?Um9oaXQ=?= | last post by:
I have a timer object that calls UpdateWindow(). The WM_TIMER message is processed in the main Win32 message loop for the window. However, when I run the app, the image doesn't get updated (there...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
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...
0
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...
0
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...
0
agi2029
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,...
0
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...

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.