Simple drawing question

NicoVB

Well-known member
Joined
Jan 2, 2002
Messages
160
Location
Belgium
Code:
  button1_Click      

pnlLinks.Invalidate()
Dim i As Object
For each i In concoll
 i.BackColor = Color.Transparent
Next


Dim g As Graphics
        g = pnlLinks.CreateGraphics
        g.FillRectangle(New SolidBrush(ColorTranslator.FromHtml("#003366")), rect)
        g.DrawRectangle(New Pen(ColorTranslator.FromHtml("#99FF00")), rect)
        CTL.BackColor = ColorTranslator.FromHtml("#003366")
        CType(CTL.Tag, Panel).BackColor = ColorTranslator.FromHtml("#003366")
        g.Dispose()

This is the code I use for my drawing of a rectangle. But what happens: I can see that there is drawn a rectangle one millisecond, but the rectangle disappears instantly. Why is that??
 
You need to put all drawing code in your Paint event, otherwise it will simply be painted over as soon as you draw on it.

If you want to force the control to redraw itself do this:
Code:
[i]Control[/i].Invalidate()
 
Back
Top