Results 1 to 4 of 4

Thread: question about replacement for image control array upgrading from VB6

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    question about replacement for image control array upgrading from VB6

    I am upgrading my program from VB6 to VB2010. In VB6 I am using about 200 pictureboxes loaded at runtime starting with one of each different picture

    Private Sub Form_Load()
    Image1(0).Top = 2340
    Image1(0).Left = Screen.Width - 1300
    Image1(0).ZOrder 0
    For i = 1 To 19
    Load Image1(i)
    Image1(i).Top = 2340
    Image1(i).Left = Screen.Width - 1300
    Image1(i).Visible = True
    Image1(i).ZOrder 0
    Next
    end sub

    I search through all the pictureboxes then snap the picturebox the user dropped to a picturebox that is close by.

    Private Sub CabinetWithDrawers_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    For i = Image1().LBound To Image1().UBound
    If Image2(Index).Left >= Image1(i).Left + 623 And Image2(Index).Left <= Image1(i).Left + 1567 _
    And Image2(Index).Top = Image1(i).Top Then
    'snap to the right
    Image2(Index).Left = Image1(i).Left + 1202
    Exit For
    Next
    end sub

    What can i use instead of control arrays in VB2010 to get the same functionality as in VB6, or does VB2010 use control arrays?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: question about replacement for image control array upgrading from VB6

    There's no design time support for control arrays in VB.NET because it's not needed. You can certainly create an array of controls in code though, just as you create any array. You can also index the form's Controls collection by ordinal or name, so you can use a loop to get all similarly named and/or typed controls. You can also use a LINQ query to get all the controls that match a certain condition and then loop through those.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    B.C. Canada
    Posts
    206

    Re: question about replacement for image control array upgrading from VB6

    Quote Originally Posted by jmcilhinney View Post
    There's no design time support for control arrays in VB.NET because it's not needed. You can certainly create an array of controls in code though, just as you create any array. You can also index the form's Controls collection by ordinal or name, so you can use a loop to get all similarly named and/or typed controls. You can also use a LINQ query to get all the controls that match a certain condition and then loop through those.
    I'm creating indexed CabinetWithDrawers at runtime in VB6 like this, how do i in VS2010?

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    CabinetWithDrawers(0).Top = 4455
    CabinetWithDrawers(0).Left = Screen.Width - 2100
    CabinetWithDrawers(0).ZOrder(0)
    For i = 21 To 39
    Load(CabinetWithDrawers(i))
    CabinetWithDrawers(i).Top = 4455
    CabinetWithDrawers(i).Left = Screen.Width - 2100
    CabinetWithDrawers(i).Visible = True
    CabinetWithDrawers(i).ZOrder(0)
    Next

    CabWithDoorsLabel.Top = 1940
    CabWithDoorsLabel.Left = Screen.Width - 2100
    CabWithDoors(0).Top = 2340
    CabWithDoors(0).Left = Screen.Width - 2100 '1500
    CabWithDoors(0).ZOrder 0
    For i = 1 To 19
    Load CabWithDoors(i)
    CabWithDoors(i).Top = 2340
    CabWithDoors(i).Left = Screen.Width - 2100 '1500
    CabWithDoors(i).Visible = True
    CabWithDoors(i).ZOrder 0
    Next

    End Sub

    This works in VS2010 but it won't allow me to identify which CabinetWithDrawers(index) was clicked
    Private Sub CabinetWithDrawers_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CabinetWithDrawers.MouseDown
    StoredX = e.X
    StoredY = e.Y
    End Sub

    This works in VS2010 but it won't allow me to identify which CabinetWithDrawers(index) is moving
    Private Sub CabinetWithDrawers_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CabinetWithDrawers.MouseMove
    If e.Button = MouseButtons.Left Then
    CabinetWithDrawers.Top = CabinetWithDrawers.Top - (StoredY - e.Y)
    CabinetWithDrawers.Left = CabinetWithDrawers.Left - (StoredX - e.X)
    End If
    End Sub

    In VB6: This is where i loop through all the CabWithDoors(i) to find one to snap to if close enough, how do i do this in VS2010?
    Private Sub CabinetWithDrawers_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

    'snap the sides together with CabWithDoors
    For i = CabWithDoors().LBound To CabWithDoors().UBound
    'loop if cabinet is in pile
    If CabWithDoors(i).Left > (Image1.Width + Image1.Left) Or i = Index Then
    GoTo backtop2
    End If
    'if close to the right side and the tops are at the same height
    If CabinetWithDrawers(Index).Left >= CabWithDoors(i).Left + 623 And CabinetWithDrawers(Index).Left <= CabWithDoors(i).Left + 1567 _
    And CabinetWithDrawers(Index).Top = CabWithDoors(i).Top Then
    'snap to the right
    CabinetWithDrawers(Index).Left = CabWithDoors(i).Left + 1202
    Exit For
    'if close to the left side and the tops are at the same height
    ElseIf CabinetWithDrawers(Index).Left >= CabWithDoors(i).Left - 1567 And CabinetWithDrawers(Index).Left <= CabWithDoors(i).Left + 622 _
    And CabinetWithDrawers(Index).Top = CabWithDoors(i).Top Then
    'then snap to the left
    CabinetWithDrawers(Index).Left = CabWithDoors(i).Left - 1202
    Exit For
    'if the tops are at different heights then
    ElseIf CabinetWithDrawers(Index).Left >= CabWithDoors(i).Left - 1567 And CabinetWithDrawers(Index).Left <= CabWithDoors(i).Left - 623 _
    And CabinetWithDrawers(Index).Top <> CabWithDoors(i).Top Then
    'snap to the left
    CabinetWithDrawers(Index).Left = CabWithDoors(i).Left - 1202
    Exit For
    ElseIf CabinetWithDrawers(Index).Left >= CabWithDoors(i).Left - 622 And CabinetWithDrawers(Index).Left <= CabWithDoors(i).Left + 622 _
    And CabinetWithDrawers(Index).Top <> CabWithDoors(i).Top Then
    'snap to the middle
    CabinetWithDrawers(Index).Left = CabWithDoors(i).Left
    Exit For
    ElseIf CabinetWithDrawers(Index).Left >= CabWithDoors(i).Left + 623 And CabinetWithDrawers(Index).Left <= CabWithDoors(i).Left + 1567 _
    And CabinetWithDrawers(Index).Top <> CabWithDoors(i).Top Then
    'snap to the right
    CabinetWithDrawers(Index).Left = CabWithDoors(i).Left + 1202
    Exit For
    End If
    backtop2:
    Next

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: question about replacement for image control array upgrading from VB6

    I'm afraid all that code is too hard to read without CODE or VBCode tags for formatting. It's not really needed anyway. There's an absolute ton of information out there on what to do in VB.NET where you would have used a control array in VB6.

    http://www.google.com.au/search?q=co...ient=firefox-a
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width