On a msdn forum A user named Acamar, posted some code for the project I am doing
It does a lot now I need to ceate a class of objects and make an array to store the location and add a machineId to each location.
So each time it draws something it will give me a popup asking for machineID and using the location will store it in a table.
Then Use the machineID to draw more information for each machine. Since you can only draw information about each machine at a time.
Cannot use next or previous to scroll to all of them. So I think.... I will only need 1 sql statement as it will always grab the same info
[FONT=Courier new][COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Class[/COLOR] Form1
[COLOR=#0000ff]Dim[/COLOR] SizeW [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 20
[COLOR=#0000ff]Dim[/COLOR] SizeH [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 20
[COLOR=#0000ff]Dim[/COLOR] Plan(SizeW - 1, SizeH - 1) [COLOR=#0000ff]As[/COLOR] CellValue
[COLOR=#0000ff]Dim[/COLOR] Command [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = -1
[COLOR=#0000ff]Dim[/COLOR] RND [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]New[/COLOR] Random
[COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] btnClear_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] btnClear.Click
Command = 0
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
[/COLOR] [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] btnAdd_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] btnAdd.Click
Command = 1
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
[/COLOR] [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] PictureBox1_Click([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] System.Object, [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.EventArgs) [COLOR=#0000ff]Handles[/COLOR] PictureBox1.Click
[COLOR=#0000ff]Dim[/COLOR] CellW [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Width \ SizeW
[COLOR=#0000ff]Dim[/COLOR] CellH [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Height \ SizeH
[COLOR=#0000ff]Dim[/COLOR] P [COLOR=#0000ff]As[/COLOR] Point = PointToClient(MousePosition)
[COLOR=#0000ff]Dim[/COLOR] X [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = (P.X - PictureBox1.Left) \ CellW
[COLOR=#0000ff]Dim[/COLOR] Y [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = (P.Y - PictureBox1.Top) \ CellH
[COLOR=#0000ff]If[/COLOR] Command <> -1 [COLOR=#0000ff]Then
[/COLOR] [COLOR=#0000ff]If[/COLOR] Plan(X, Y) [COLOR=#0000ff]Is[/COLOR] [COLOR=#0000ff]Nothing[/COLOR] [COLOR=#0000ff]Then[/COLOR] Plan(X, Y) = [COLOR=#0000ff]New[/COLOR] CellValue
[COLOR=#0000ff]Select[/COLOR] [COLOR=#0000ff]Case[/COLOR] Command
[COLOR=#0000ff]Case[/COLOR] 0 : Plan(X, Y).CellShape = 0
[COLOR=#0000ff]Case[/COLOR] 1
[COLOR=#0000ff]If[/COLOR] rbnCircle.Checked [COLOR=#0000ff]Then
[/COLOR] Plan(X, Y).CellShape = Shape.Circle
[COLOR=#0000ff]Else
[/COLOR] Plan(X, Y).CellShape = Shape.Square
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
[/COLOR] [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Select
[/COLOR] Plan(X, Y).CellName = TextBox1.Text
Plan(X, Y).CellColor = Color.FromArgb(255, RND.Next(1, 256), RND.Next(1, 256), RND.Next(1, 256))
PictureBox1.Invalidate()
Command = -1 [COLOR=#008000]'One click only per selection
[/COLOR] [COLOR=#0000ff]Else
[/COLOR] [COLOR=#0000ff]If[/COLOR] [COLOR=#0000ff]Not[/COLOR] Plan(X, Y) [COLOR=#0000ff]Is[/COLOR] [COLOR=#0000ff]Nothing[/COLOR] [COLOR=#0000ff]Then
[/COLOR] TextBox1.Text = Plan(X, Y).CellName
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
[/COLOR] [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
[/COLOR] [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
[/COLOR] [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] PictureBox1_Paint([COLOR=#0000ff]ByVal[/COLOR] sender [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Object[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] e [COLOR=#0000ff]As[/COLOR] System.Windows.Forms.PaintEventArgs) [COLOR=#0000ff]Handles[/COLOR] PictureBox1.Paint
[COLOR=#0000ff]Dim[/COLOR] W [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Width
[COLOR=#0000ff]Dim[/COLOR] H [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Height
[COLOR=#0000ff]Dim[/COLOR] CellW [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = W \ SizeW
[COLOR=#0000ff]Dim[/COLOR] CellH [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = H \ SizeH
[COLOR=#0000ff]Dim[/COLOR] P [COLOR=#0000ff]As[/COLOR] Pen = [COLOR=#0000ff]New[/COLOR] Pen(Color.Gray, 1)
[COLOR=#0000ff]For[/COLOR] I [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 0 [COLOR=#0000ff]To[/COLOR] W [COLOR=#0000ff]Step[/COLOR] CellW
e.Graphics.DrawLine(P, I, 0, I, H)
[COLOR=#0000ff]Next
[/COLOR] [COLOR=#0000ff]For[/COLOR] I [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 0 [COLOR=#0000ff]To[/COLOR] H [COLOR=#0000ff]Step[/COLOR] CellH
e.Graphics.DrawLine(P, 0, I, W, I)
[COLOR=#0000ff]Next
[/COLOR] [COLOR=#0000ff]For[/COLOR] i [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 0 [COLOR=#0000ff]To[/COLOR] SizeW - 1
[COLOR=#0000ff]For[/COLOR] j [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = 0 [COLOR=#0000ff]To[/COLOR] SizeH - 1
[COLOR=#0000ff]If[/COLOR] [COLOR=#0000ff]Not[/COLOR] Plan(i, j) [COLOR=#0000ff]Is[/COLOR] [COLOR=#0000ff]Nothing[/COLOR] [COLOR=#0000ff]Then
[/COLOR] fillcell(e.Graphics, i, j, Plan(i, j).CellColor, Plan(i, j).CellShape)
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
[/COLOR] [COLOR=#0000ff]Next
[/COLOR] [COLOR=#0000ff]Next
[/COLOR] [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
[/COLOR] [COLOR=#0000ff]Private[/COLOR] [COLOR=#0000ff]Sub[/COLOR] fillcell([COLOR=#0000ff]ByVal[/COLOR] g [COLOR=#0000ff]As[/COLOR] Graphics, [COLOR=#0000ff]ByVal[/COLOR] I [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] j [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR], [COLOR=#0000ff]ByVal[/COLOR] C [COLOR=#0000ff]As[/COLOR] Color, [COLOR=#0000ff]ByVal[/COLOR] S [COLOR=#0000ff]As[/COLOR] Shape)
[COLOR=#0000ff]Dim[/COLOR] CellW [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Width \ SizeW
[COLOR=#0000ff]Dim[/COLOR] CellH [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = PictureBox1.Height \ SizeH
[COLOR=#0000ff]Dim[/COLOR] x [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = I * CellW
[COLOR=#0000ff]Dim[/COLOR] y [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Integer[/COLOR] = j * CellH
[COLOR=#0000ff]Select[/COLOR] [COLOR=#0000ff]Case[/COLOR] S
[COLOR=#0000ff]Case[/COLOR] Shape.Blank [COLOR=#008000]' Do Nothing
[/COLOR] [COLOR=#0000ff]Case[/COLOR] Shape.Square
g.FillRectangle([COLOR=#0000ff]New[/COLOR] SolidBrush(C), [COLOR=#0000ff]New[/COLOR] Rectangle(x, y, CellW, CellH))
[COLOR=#0000ff]Case[/COLOR] Shape.Circle
g.FillEllipse([COLOR=#0000ff]New[/COLOR] SolidBrush(C), [COLOR=#0000ff]New[/COLOR] Rectangle(x, y, CellW, CellH))
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Select
[/COLOR] [COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
End[/COLOR] [COLOR=#0000ff]Class
Friend[/COLOR] [COLOR=#0000ff]Class[/COLOR] CellValue
[COLOR=#0000ff]Public[/COLOR] CellColor [COLOR=#0000ff]As[/COLOR] Color = Color.White
[COLOR=#0000ff]Public[/COLOR] CellShape [COLOR=#0000ff]As[/COLOR] Shape = Shape.Blank
[COLOR=#0000ff]Public[/COLOR] CellName [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]String[/COLOR] = [COLOR=#a31515]""
[/COLOR][COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Class
Friend[/COLOR] [COLOR=#0000ff]Enum[/COLOR] Shape
Blank
Square
Circle
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Enum[/COLOR][/FONT]