VB-code that generates pictureboxes

March 24, 2009 at 07:55:06
Specs: Windows Vista
First of all, I'm pretty much a beginner concerning Visual Basic.

I wrote the next code to generate some pictureboxes on the leftside of a splitcontainer.
(from a variabele, I want to create a field of pictureboxes, variabel+2 in lenght and variabale+2 in heigth. Then i want to fill them)

If someone could tell me why this won't work, and how it will work... It would be greatly appreciated.

Public Class Othello
    Public IntSize As Integer
    Public arplaatjes(10, 2) As Image
    
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        arplaatjes(0, 0) = Image.FromFile("images\4.png")
        arplaatjes(0, 1) = Image.FromFile("images\4zwart.png")
        arplaatjes(0, 2) = Image.FromFile("images\4wit.png")
        arplaatjes(1, 0) = Image.FromFile("images\3T.png")
        arplaatjes(1, 1) = Image.FromFile("images\3Tzwart.png")
        arplaatjes(1, 2) = Image.FromFile("images\3Twit.png")
        arplaatjes(2, 0) = Image.FromFile("images\3L.png")
        arplaatjes(2, 1) = Image.FromFile("images\3Lzwart.png")
        arplaatjes(2, 2) = Image.FromFile("images\3Lwit.png")
        arplaatjes(3, 0) = Image.FromFile("images\3R.png")
        arplaatjes(3, 1) = Image.FromFile("images\3Rzwart.png")
        arplaatjes(3, 2) = Image.FromFile("images\3Rwit.png")
        arplaatjes(4, 0) = Image.FromFile("images\3B.png")
        arplaatjes(4, 1) = Image.FromFile("images\3Bzwart.png")
        arplaatjes(4, 2) = Image.FromFile("images\3Bwit.png")
        arplaatjes(5, 0) = Image.FromFile("images\2LT.png")
        arplaatjes(5, 1) = Image.FromFile("images\2LTzwart.png")
        arplaatjes(5, 2) = Image.FromFile("images\2LTwit.png")
        arplaatjes(6, 0) = Image.FromFile("images\2RT.png")
        arplaatjes(6, 1) = Image.FromFile("images\2RTzwart.png")
        arplaatjes(6, 2) = Image.FromFile("images\2RTwit.png")
        arplaatjes(7, 0) = Image.FromFile("images\2LB.png")
        arplaatjes(7, 1) = Image.FromFile("images\2LBzwart.png")
        arplaatjes(7, 2) = Image.FromFile("images\2LBwit.png")
        arplaatjes(8, 0) = Image.FromFile("images\2RB.png")
        arplaatjes(8, 1) = Image.FromFile("images\2RBzwart.png")
        arplaatjes(8, 2) = Image.FromFile("images\2RBwit.png")
        arplaatjes(9, 0) = Image.FromFile("images\E.png")
        arplaatjes(9, 1) = Image.FromFile("images\Ezwart.png")
        arplaatjes(9, 2) = Image.FromFile("images\Ewit.png")
        arplaatjes(10, 0) = Image.FromFile("images\Ster.png")
        arplaatjes(10, 1) = Image.FromFile("images\4zwart.png")
        arplaatjes(10, 2) = Image.FromFile("images\4wit.png")
        Makenbord(10)
    End Sub

    Public Sub Makenbord(ByVal Breedte As Integer)
        Dim BreedteTotaal As Integer = Breedte + 2
        Dim aantalVakjes As Integer = CInt(BreedteTotaal ^ 2 - 1)
        Dim Split1 As New SplitContainer
        Dim strnaam(CInt(BreedteTotaal ^ 2 - 1)) As String
       
        For i As Integer = 1 To aantalVakjes + 1
            strnaam(i - 1) = "PB" & CStr(i)
        Next

        Split1.Location = New System.Drawing.Point(0, 0)
        Split1.Dock = System.Windows.Forms.DockStyle.Fill
        Split1.ForeColor = System.Drawing.SystemColors.Control

        For i As Integer = 0 To aantalVakjes
            Dim PB As New PictureBox

            PB.Height = 50
            PB.Width = 50
            PB.Left = (i Mod BreedteTotaal) * 50
            PB.Top = (i \ BreedteTotaal * 50)
            PB.Padding = New Padding(0, 0, 0, 0)
            Split1.Panel1.Controls.Add(PB)
            PB.Name = strnaam(i)
            Select Case i
                Case Is <= BreedteTotaal
                    PB.Image = arplaatjes(9, 0)
                Case Is = BreedteTotaal + 1
                    PB.Image = arplaatjes(5, 0)
                Case Is < BreedteTotaal * 2 - 2
                    PB.Image = arplaatjes(1, 0)
                Case Is = BreedteTotaal * 2 - 2
                    PB.Image = arplaatjes(6, 0)
                Case Is <= CInt(BreedteTotaal ^ 2) - 2 * BreedteTotaal
                    If i Mod BreedteTotaal = 0 Or i Mod BreedteTotaal = BreedteTotaal - 1 Then
                        PB.Image = arplaatjes(9, 0)
                    ElseIf i Mod BreedteTotaal = 1 Then
                        PB.Image = arplaatjes(2, 0)
                    ElseIf i Mod BreedteTotaal = BreedteTotaal - 2 Then
                        PB.Image = arplaatjes(3, 0)
                    Else
                        PB.Image = arplaatjes(0, 0)
                    End If
                Case Is = BreedteTotaal * BreedteTotaal - 2 * BreedteTotaal + 1
                    PB.Image = arplaatjes(7, 0)
                Case Is < BreedteTotaal * BreedteTotaal - BreedteTotaal - 2
                    PB.Image = arplaatjes(4, 0)
                Case Is = BreedteTotaal * BreedteTotaal - BreedteTotaal - 2
                    PB.Image = arplaatjes(8, 0)
                Case Is >= CInt(BreedteTotaal ^ 2) - BreedteTotaal - 1
                    PB.Image = arplaatjes(9, 0)
            End Select

        Next
    End Sub
End Class


See More: VB-code that generates pictureboxes

Report •


#1
March 24, 2009 at 08:02:24
I've only done a quick glance of the code, but do you ever call Me.Controls.Add(PB)? Or Me.Controls.Add(Split1)?

Report •

#2
March 25, 2009 at 01:01:06
AH...

I have a controls.add(pb) but i kind of forgot to add the split...
I added it and now he draws something. But the left side of the split is a bit to small. Is there a way to set the width of the left panel?

I looked it up and it was something with distance, but i can't get it to work.

PS. Thanx a lot for the last advice. I looked over it for about an hour and never noticed i missed that line.


Report •

#3
March 25, 2009 at 11:04:06
It should be Split1.SplitterDistance = [some Integer], is that not working?

Report •

Related Solutions


Ask Question