jimday1982 Posted August 25, 2003 Posted August 25, 2003 Does anyone know of an easy way to make a grid appear on a picture box that already has a picture on it with the press of a button. I am having trouble drawing it correctly due to varying picture sizes. Anyone have any experience with this? Thank you! Quote
rustyd Posted August 25, 2003 Posted August 25, 2003 In the picturebox paint event I loop throught the number Dim Line1 As PointF Dim Line2 As PointF Dim ColSize As Single Dim RowSize As Single Dim nRows As Integer Dim nCols As Integer Dim penBlack As New Drawing.Pen(System.Drawing.Color.Black, 1) nRows = 9 nCols = 18 RowSize = Me.PictureBox1.Height / nRows ColSize = Me.PictureBox1.Width / nCols ' Draw Vertical grid Line1.X = ColSize Line1.Y = 0 Line2.X = ColSize Line2.Y = Me.PictureBox1.Height For X = 0 To nCols e.Graphics.DrawLine(penBlack, Line1, Line2) Line1.X = Line1.X + ColSize Line2.X = Line2.X + ColSize Next X ' Draw Horizontal grid Line1.X = 0 Line1.Y = RowSize Line2.X = Me.PictureBox1.Width Line2.Y = RowSize For X = 0 To nRows e.Graphics.DrawLine(penBlack, Line1, Line2) Line1.Y = Line1.Y + RowSize Line2.Y = Line2.Y + RowSize Next X Have to do it on the paint event or you won't see it. If something in the grid changes, must call PictureBox1.Invalidate() to repaint the picturebox grid. Quote rustyd
*Gurus* divil Posted August 26, 2003 *Gurus* Posted August 26, 2003 Take a look at the ControlPaint class. It has a DrawGrid method which will probably be a lot faster. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Hamburger1984 Posted August 26, 2003 Posted August 26, 2003 ....or you use a System.Drawing.Drawing2D.Hatchbrush... should also be faster than drawing the grid line by line.... Andreas Quote
Nazdor Posted August 28, 2003 Posted August 28, 2003 Suggestion: Draw the grid onto a separate in-memory bitmap (that you keep, so you only have to do it once) then draw the bitmap over the top of the existing image. Possibly use a colormatrix to set a transparent background colour. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.