|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom double bufferI've got some problem doing double buffer. Here is my problem: I've got custom control on which i paint some data (chat messages, lets call it ChatControl), this control is puted on a scrollable panel. Of course i've set right styles on a ChatControl: //styles this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.ResizeRedraw, true); Everything is ok,but i've got some performance problems. Chat messages arrived in every 5 seconds, and i call on ChatControl Refresh(), so my OnPaint method is called - and thats ok. But control is repainted more times than on in every 5 second refresh: user used scroll, or something like that. And now i want to made some additional double buffer, because i want to draw remembered graphic (thru bitmap), than draw it again - because its neccesery when i only refresh control. I know i should do something like this: Bitmap bmp = new Bitmap(this.ClientRectangle.Witdh, this.ClientRectangle.Height); Graphics g = Graphics.FromImage(bmp); and than i should draw on g but there is a "small" problem - beacuse i know control size after i draw something (thats depends at chat messages count)! so how i can get a bitmap from my base graphics or how to create bitmap that will resize automaticly to my graphic size ? Or .... maybe somebody got any idea? regards kuba florczyk You should possibly consider manual double buffering. What you're doing is
essentially double buffering and then writing that the the systems back-buffer so you might as well do it yourself. Windows Forms Tips and Tricks has an article on double buffering and shows you how to manage a back-buffer that changes size in response to the OnSizeChanged method calls. -- Show quoteBob Powell [MVP] Visual C#, System.Drawing Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article. "Kuba Florczyk" <c***@poczta.onet.pl> wrote in message news:%23GO1sP10EHA.3504@TK2MSFTNGP12.phx.gbl... > Hi > > I've got some problem doing double buffer. > Here is my problem: > I've got custom control on which i paint some data (chat messages, lets call > it ChatControl), this control is puted on a scrollable panel. > Of course i've set right styles on a ChatControl: > > //styles > this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); > this.SetStyle(ControlStyles.DoubleBuffer, true); > this.SetStyle(ControlStyles.UserPaint, true); > this.SetStyle(ControlStyles.ResizeRedraw, true); > > Everything is ok,but i've got some performance problems. Chat messages > arrived in every 5 seconds, and i call on ChatControl Refresh(), so my > OnPaint method is called - and thats ok. But control is repainted more times > than on in every 5 second refresh: user used scroll, or something like that. > > And now i want to made some additional double buffer, because i want to draw > remembered graphic (thru bitmap), than draw it again - because its neccesery > when i only refresh control. I know i should do something like this: > > Bitmap bmp = new Bitmap(this.ClientRectangle.Witdh, > this.ClientRectangle.Height); > Graphics g = Graphics.FromImage(bmp); > > and than i should draw on g > > but there is a "small" problem - beacuse i know control size after i draw > something (thats depends at chat messages count)! so how i can get a bitmap > from my base graphics or how to create bitmap that will resize automaticly > to my graphic size ? Or .... maybe somebody got any idea? > > regards > kuba florczyk > > |
|||||||||||||||||||||||