473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Draw a Grid on a UserControl

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
1 3518
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
0
by: Kelly Johnson | last post by:
This is what I want to do: I want to create a UserControl that will hold a grid. This UserControl will be used specifically to display data about users, with that data appearing in the grid. ...
1
by: Steve | last post by:
Hi, I have a UserControl which I would like the user to be able to configure through the property grid at runtime. How can I hide certain properties that you get as standard such as Anchor and...
1
by: gerry | last post by:
I have seen many posts regarding a the grid SortCommand even not firing but haven't been able to determine what the problem is. The grid is contained in a UserControl which is added to the page...
8
by: Frank | last post by:
Hello, I have a form in which I draw a grid in the paint event. Works fine, except when using the scrollbars. Autoscroll is switched on, I use doublebuffering and userpaint and...
10
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover...
1
by: margelos | last post by:
I have created the following usercontrol public class RegisterUser : TemplatedWebControl { private VisFields _vfields = new VisFields(); public VisFields VisibleFields { get { return...
2
by: Sagaert Johan | last post by:
Hi I want to draw grips around my usercontrol. Becorse the grips are around the customcontrol they are outside the controls drawing area. I tried setting the Region to infinit but that does not...
7
by: yugas | last post by:
how to write a c program to draw a rectangular grid having 10 rows and 10 columns. please help me.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.