By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

Draw a Grid on a UserControl

P: n/a
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
Jul 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
"Tom" wrote:
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
Jul 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.