Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET General (http://www.xtremevbtalk.com/-net-general/)
-   -   Unexpected Index Change. (http://www.xtremevbtalk.com/-net-general/328648-unexpected-index-change.html)

Goggy 06-02-2017 01:19 AM

Unexpected Index Change.
Could any one hint me in the right direction why the code shown below, (not every time, but once in a while) would change the index of the controls in the controlcollection?


    Public Overrides Function Layout(container As Object, layoutEventArgs As LayoutEventArgs) As Boolean
        Parent = TryCast(container, TabControl)
        If Parent IsNot Nothing Then
            For I As Integer = 0 To Parent.Controls.Count - 1
                Tp = TryCast(Parent.Controls.Item(I), TabPage)
                If Tp IsNot Nothing Then
                    With Tp
                        .Header.Bounds = New Rectangle(I * Parent.HeaderWidth.ToInteger, 0, Parent.HeaderWidth.ToInteger, Parent.HeaderHeight.ToInteger)
                        .Visible = Tp.Header.IsSelected
                    End With
                End If
        End If
        Return False
    End Function

passel 06-05-2017 02:13 PM

I don't know specifically, but I've found that the order the controls are in the forms collection depend on the order they are written in the .frm file. Since the .frm file is updated with code quite often, so re-written quite often, the order of things in the file may change.
For instance, it seems quite often that I add controls to the form and save the project, that the controls are written to the file in the reverse order that I added them, the first time. It may stay that way for a while, but further edits to the form do seem to sometimes cause the order in the .frm file to change.
VB doen't care about the order that controls are added to the collection and you shouldn't rely on the controls being in a particular order either.

Goggy 06-06-2017 12:57 AM

Thank you Passel for this clear answer. :)

All times are GMT -6. The time now is 04:37 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.