title: Form flickering when using buttons
body: <p>I'm trying to draw a board and have the user perform actions when a button is pressed.</p>
  
  <p>It seems that hovering the button calls form's <code>Paint</code> which redraws the board and triggers a flickering of the form. </p>
  
  <p>While having the board redrawn on <code>Paint</code> is normal (use actions will determine changes on the board), is there any way I can avoid the flickering? Maybe call form's <code>Invalidate</code> on certain events? Maybe find an alternative to <code>CreateGraphics</code>? </p>
  
  <pre><code>open System.Windows.Forms 
  open System.Drawing
  
  type BoardForm() = 
      let button = new Button()
  
      let initializeButton (button:Button) left top caption sizeX sizeY enabled callback = 
          button.Text&lt;-caption
          button.Top&lt;-top
          button.Left&lt;-left
          button.Size&lt;-new Size(sizeX,sizeY)
          button.Click.Add(callback)
  
      let drawBoard (form:Form) (x:int) (y:int) (width:int) (height:int) =         
          let brushBoard = new SolidBrush(Color.Beige)
          let g = form.CreateGraphics()
          g.FillRectangle(brushBoard, x, y, width, height)
  
          let cellSize = 10
          let cellsX = 10
          let cellsY = 10
          use pen = new Pen(Brushes.Black)
          for i in [0..cellsY] do
              g.DrawLine(pen, x, y+i*cellSize, x+cellsX*cellSize, y+i*cellSize)
  
      let drawButtons (form:Form) =
          let left = 10
          let top = 300
          let buttonWidth = 50
          let buttonHeight = 30
  
          initializeButton button left top "Ping" 50 buttonHeight true (fun _ -&gt; printfn "I was pushed")
          [button] |&gt; Seq.cast&lt;Control&gt; |&gt; Array.ofSeq |&gt; form.Controls.AddRange
  
      let initializeForm() =         
          let formWidth = 240
          let formHeight = 400
          let x = 10
          let y = 10
          let width = 200
          let height = 200
          let form = new Form(Width=formWidth, Height=formHeight, Visible=true, Text="Some form", TopMost=true)        
  
          form.Paint.Add(fun e -&gt; drawBoard form x y width height) 
  
          drawButtons form    
  
      member this.Start() =
          initializeForm()
  
  let boardForm = new BoardForm()
  boardForm.Start()
  </code></pre>