hog Posted June 20, 2003 Posted June 20, 2003 I asked this before (I think) but here goes.. I have code in a forms Paint event that draws a non regular shape form and fills the backcolor property. This on its own works fine with no flicker. But say I add six controls to the form and also have code to set their backcolor property. Now I get a flicker as each control is modified and I can see each control in turn change colour. Question is this: Is there a way to disable screen refresh so all the modifications take place then the screen is refreshed in one go? Quote My website
*Experts* mutant Posted June 20, 2003 *Experts* Posted June 20, 2003 Did you try setting DoubleBuffering? Quote
hog Posted June 20, 2003 Author Posted June 20, 2003 Dumb question coming....erm how? Quote My website
*Experts* mutant Posted June 20, 2003 *Experts* Posted June 20, 2003 For a form, type: SetStyle(DoubleBuffering,true) In form load or the constructor for example. If you want to use it in controls you have to inherit a class from the control and set the same thing in there, you have to do that, becuase this is protected in controls. Quote
hog Posted June 20, 2003 Author Posted June 20, 2003 OK I tried this: Me.SetStyle(ControlStyles.DoubleBuffer, True) and this Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True) Me.UpdateStyles() both with no success:( so I suspect your sentence re the controls may be relevant, but dumbo here appears to be in the dark regarding these things:( any chance of another gentle nudge:) Quote My website
*Experts* mutant Posted June 20, 2003 *Experts* Posted June 20, 2003 What do you mean without success? :) Is there any error or it just doesnt make anything better? As for the control, to do what I said, make a new class, inherit it from the control you want to use, then in the constructor of the control use: SetStyle(DoubleBuffer,true) SetStyle(AllPaintingInWMPAINT,true) Then instead of using the default control from the toolbox use your own control that you inherited. Quote
hog Posted June 21, 2003 Author Posted June 21, 2003 OK..it makes no difference:) So I get what you mean now, but am struggling trying to achieve it:( I haven't created a control class before and have tried this but it errors....no suprises there :) Public Class clsPictureBox Inherits System.Windows.Forms.PictureBox Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub End Class I then read a thread which said about adding a user controls or inherited user controls but am getting more lost as I go:(:( Quote My website
*Experts* mutant Posted June 21, 2003 *Experts* Posted June 21, 2003 That should be all good except there is no IntializeComponent sub in there, which you dont need. So remove the call to it. :) Quote
hog Posted June 21, 2003 Author Posted June 21, 2003 OK...still no joy, this is what I have so far: Public Class clsPictureBox Inherits System.Windows.Forms.PictureBox Public Sub New() MyBase.New() 'Add any initialization after the InitializeComponent() call SetStyle(ControlStyles.DoubleBuffer, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) End Sub End Class Then in my form I have manually entered this code? Friend WithEvents picGameField As clsPictureBox Me.picGameField = New clsPictureBox ' 'picGameField ' Me.picGameField.BackColor = System.Drawing.Color.FromArgb(CType(255, Byte), CType(192, Byte), CType(255, Byte)) Me.picGameField.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.picGameField.Location = New System.Drawing.Point(440, 32) Me.picGameField.Name = "picGameField" Me.picGameField.Size = New System.Drawing.Size(163, 304) Me.picGameField.Visible = True no errors occur but the picturebox does not appear either. New ground this, creating my own controls....can u tell :) Quote My website
hog Posted June 21, 2003 Author Posted June 21, 2003 Ah hold the phone... just added this line: Me.Controls.Add(Me.picNextBlock) and it appears so now to do the rest and see if it resolves the flicker:) Quote My website
hog Posted June 21, 2003 Author Posted June 21, 2003 (edited) no, still get the flicker:( No matter what I try the screen flickers. Is there no way to just tell VB, don't display the form changes until they have all been made sonething like: ScreenUpdating(False) button1.backcolor=.... button2.backcolor=.... button3.backcolor=.... button4.backcolor=.... button5.backcolor=.... button6.backcolor=.... other modifications..... ScreenUpdating(True) Edited June 21, 2003 by hog Quote My website
*Experts* mutant Posted June 21, 2003 *Experts* Posted June 21, 2003 How fast are you changing the backgrounds? PictureBoxes are not recommended for something that changes fast as they are slow. Quote
hog Posted June 21, 2003 Author Posted June 21, 2003 Well I have a non regular shape form with 4 buttons, 2 picture boxes and three labels. What I am tryint ot achieve is to allow the user to select the back colour of their choice, which results in the forms backcolor changing and all the controls backcolors to a off shade of the chosen colour. What happens now is I see each control in turn change colour which results in a flicker effect on the form. Quote My website
*Experts* mutant Posted June 21, 2003 *Experts* Posted June 21, 2003 I tried to do something similar with 12 pictureboxes, randomly changing color in a 20millisecond timer. No flicker at all. I dont think I can help you more without seeing more of your code :). Quote
hog Posted June 21, 2003 Author Posted June 21, 2003 Here ya go then:) Public Sub PaintShape() Dim graphPath As New Drawing2D.GraphicsPath Dim gfxGameGraphics As Graphics Dim brBrushSquare As Drawing2D.PathGradientBrush Dim arrLiner1() As Point = {New Point(323, 410), New Point(329, 368), New Point(354, 314), New Point(368, 281)} Dim arrLiner2() As Point = {New Point(27, 319), New Point(69, 300), New Point(87, 320), New Point(101, 292)} Dim arrLiner3() As Point = {New Point(773, 465), New Point(695, 320), New Point(690, 300), New Point(680, 290)} Dim arrLiner4() As Point = {New Point(62, 246), New Point(83, 210), New Point(110, 230), New Point(122, 185)} Dim arrLiner5() As Point = {New Point(867, 123), New Point(865, 123), New Point(870, 115), New Point(874, 111)} graphPath.AddBeziers(arrShape) gfxGameGraphics = Graphics.FromHwnd(Me.Handle) brBrushSquare = New Drawing2D.PathGradientBrush(graphPath) gfxGameGraphics.FillPath(New SolidBrush(clrColour), graphPath) gfxGameGraphics.DrawBeziers(New Pen(Color.Black, 1), arrLiner1) gfxGameGraphics.DrawBeziers(New Pen(Color.Black, 1), arrLiner2) gfxGameGraphics.DrawBeziers(New Pen(Color.Black, 1), arrLiner3) gfxGameGraphics.DrawBeziers(New Pen(Color.Black, 1), arrLiner4) gfxGameGraphics.DrawBeziers(New Pen(Color.Black, 1), arrLiner5) Me.Region = New Region(graphPath) End Sub Private Sub frmGame_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint PaintShape() End Sub Private Sub cmdColour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColour.Click Me.ColorDialog1.ShowDialog() clrColour = Me.ColorDialog1.Color clrControlColour = Color.FromArgb(150, Me.ColorDialog1.Color) 'Me.cmdStart.BackColor = clrControlColour 'Me.cmdMinimize.BackColor = clrControlColour 'Me.cmdColour.BackColor = clrControlColour 'Me.cmdClose.BackColor = clrControlColour Me.picGameField.BackColor = clrControlColour Me.picNextBlock.BackColor = clrControlColour Me.Label1.BackColor = clrColour Me.Label2.BackColor = clrColour Me.Label3.BackColor = clrColour End Sub I've left out the array which drawss the shape in the PaintShape procedure Quote My website
*Experts* mutant Posted June 21, 2003 *Experts* Posted June 21, 2003 I copied and pasted your color changing code, not a single sign of flicker. I cant try the whole thing as you took out that array. Quote
*Experts* mutant Posted June 22, 2003 *Experts* Posted June 22, 2003 Ok, what your were doing is creating all those object all the time, which is not needed, and setting region in every paint. Look at this modified file, I hope it helps :)form1.vb Quote
hog Posted June 22, 2003 Author Posted June 22, 2003 Thnx, Mutant, I'm almost there. I had realised this may be the case and had attempted to move the offending block out of the paint procedure. However what I hav now is the shape gets draw OK, but with no outline? And when I select a new colour the controls change with no flicker, but the main form has a bizzare odd section changed only, the rest of the form remains unchanged?? Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.