Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Double buffering Custom control

Posted on 2004-03-28
8
Medium Priority
?
669 Views
Last Modified: 2007-12-19
i created a custome control that draws alot of boxes with text in them uisng GDI, I also implemented a custome scrolling, so when the user tryies to scroll i actually move the panel that contains drawing up and down.

i get alot of flicker while scrolling, i tried using double buffer techniqes but it seems to be to slow or i'm doing some thing worng,
here is the code that uses GDI to draw:


private void DrawProgram (ProgramDetail _program, int channelY)
            {
                  Bitmap offScreenBmp = new Bitmap(_program.ProgramSize.Width, _program.ProgramSize.Width);
                  Graphics GrapoffScreenDC = Graphics.FromImage(offScreenBmp);


                  Rectangle rc =  new Rectangle(new Point(XMargin , YMargin),new Size(_program.ProgramSize.Width - (XMargin * 2) ,_program.ProgramSize.Height-(YMargin * 2))) ;
                  DrawRoundedRectangle(_program.BackColor,rc,MyGraphics);
                  
                        MyGraphics.DrawString(_program.Cat,NoteFont,ProgramBrush,SideMargin + PicDim + SidePicMargin +  _program.LocationX,TopMargin + BetweenMargin + ProgramFont.Size +channelY);

                        
                        //Draw Title Text
                        MyGraphics.DrawString(_program.Title,ProgramFont,ProgramBrush,SideMargin + PicDim + SidePicMargin+_program.LocationX,TopMargin+channelY);
      
                  MyGraphics.DrawImageUnscaled(offScreenBmp,_program.LocationX,channelY);
                  MyGraphics.Dispose  ();
                  offScreenBmp.Dispose();
                  GrapoffScreenDC.Dispose  ();


            }
0
Comment
Question by:saturn_one
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:codewiz51
ID: 10700870
This isn't going to help, and it's not intended as an answer.  I primarily program in MFC/C++.  What you want to do is use a BitBlt to scroll your display rapidly.  When I searched MSDN, I only came up with unmanaged C++ examples and some VB stuff.  So, given that, I think you will need to make some windows api calls to do your scrolling.

I am relatively new to c#, and while I love the language, I have not had a good experience with graphical programming.  I get a lot of the same screen flickering and I have associated it with the performance of .Net.  I have used the techniques from this article on CodeProject to do BitBlt'ing in .Net: http://codeproject.com/vb/net/BitBlt.asp. and http://www.codeguru.com/Csharp/Csharp/cs_graphics/drawing/article.php/c6137/.

Wish I could have been more help, but realtime graphics (ie scrolling) has not been a good thing on .Net.  Everytime I end up using API calls.  The second article shows some better techniques in .Net, but for high speed scrolling, it as less that adequate.
0
 

Author Comment

by:saturn_one
ID: 10701643
i did try putting
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);

in my form constructor, but it doesn't seem to help.i stil get alot of flickers
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:TheAvenger
ID: 10701931
Why do you put it in your FORM constructor? Put it in your CONTROL constructor. When you put it in the form, it works for the form, not for the control, and you have a problem in the control.
0
 

Author Comment

by:saturn_one
ID: 10706313
I tried that too, doesn't help!
0
 

Author Comment

by:saturn_one
ID: 10706548
this, might help u guys find what the problems, i figured out that the onpaint method gets called 4-6 times every time i try to scroll! do u think that this could be causing the flicker?
0
 

Accepted Solution

by:
AnnieMod earned 0 total points
ID: 10749327
Question PAQ'd and 500 points refunded

AnnieMod
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question