Draw a Grid on a UserControl

T

Tom

Hey,

I have tried drawing a grid onto my control using the following:


Private Sub VGUI_Grid(...) Handles MyBase.Paint
Dim new_bitmap As Bitmap

' Make a new bitmap that fits the PictureBox.
new_bitmap = New Bitmap(Me.Width, Me.Height)
m_BufferGraphics = Graphics.FromImage(new_bitmap)

' Clear the new bitmap.
m_BufferGraphics.Clear(Me.BackColor)

' Draw the positioning grid.
DrawGrid(new_bitmap)

' Copy the existing bitmap's contents into
' the new bitmap.
If Not (m_BufferBitmap Is Nothing) Then
m_BufferGraphics.DrawImage(m_BufferBitmap, 0, 0)
End If

' Save the new bitmap and graphics objects.
m_BufferBitmap = new_bitmap
Me.BackgroundImage = m_BufferBitmap
End Sub


Private Sub DrawGrid(ByVal bm As Bitmap)
For Y As Integer = 0 To bm.Height - 1 Step GRID_SPACING
For X As Integer = 0 To bm.Width - 1 Step _
GRID_SPACING
bm.SetPixel(X, Y, Color.Silver)
Next X
Next Y
End Sub

But it flickers REALLY badly. I'm sure there is a better way to do this,
i just cannot see how :S

Cheers
 
G

Guest

Dont draw it every time in the paint event?

Just draw the control on form.load one time?

Or make a flag that only draws it in the paint event when needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top