saturn_one
asked on
Double buffering Custom control
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.ProgramSiz e.Width, _program.ProgramSize.Width );
Graphics GrapoffScreenDC = Graphics.FromImage(offScre enBmp);
Rectangle rc = new Rectangle(new Point(XMargin , YMargin),new Size(_program.ProgramSize. Width - (XMargin * 2) ,_program.ProgramSize.Heig ht-(YMargi n * 2))) ;
DrawRoundedRectangle(_prog ram.BackCo lor,rc,MyG raphics);
MyGraphics.DrawString(_pro gram.Cat,N oteFont,Pr ogramBrush ,SideMargi n + PicDim + SidePicMargin + _program.LocationX,TopMarg in + BetweenMargin + ProgramFont.Size +channelY);
//Draw Title Text
MyGraphics.DrawString(_pro gram.Title ,ProgramFo nt,Program Brush,Side Margin + PicDim + SidePicMargin+_program.Loc ationX,Top Margin+cha nnelY);
MyGraphics.DrawImageUnscal ed(offScre enBmp,_pro gram.Locat ionX,chann elY);
MyGraphics.Dispose ();
offScreenBmp.Dispose();
GrapoffScreenDC.Dispose ();
}
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.ProgramSiz
Graphics GrapoffScreenDC = Graphics.FromImage(offScre
Rectangle rc = new Rectangle(new Point(XMargin , YMargin),new Size(_program.ProgramSize.
DrawRoundedRectangle(_prog
MyGraphics.DrawString(_pro
//Draw Title Text
MyGraphics.DrawString(_pro
MyGraphics.DrawImageUnscal
MyGraphics.Dispose ();
offScreenBmp.Dispose();
GrapoffScreenDC.Dispose ();
}
ASKER
i did try putting
SetStyle(ControlStyles.All PaintingIn WmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer , true);
in my form constructor, but it doesn't seem to help.i stil get alot of flickers
SetStyle(ControlStyles.All
in my form constructor, but it doesn't seem to help.i stil get alot of flickers
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.
ASKER
I tried that too, doesn't help!
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.