Results 1 to 7 of 7

Thread: Minimise all MDI Chill forms .

  1. #1

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Resolved Minimise all MDI Chill forms .

    Hi there,

    Just wondered if anyone would be so nice as to help me out.

    what is the code to minimise all the MDI child forms in the parent form?

    Cheers
    Last edited by dinosaur_uk; Apr 4th, 2005 at 04:33 AM.

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Minimise all MDI Chill forms .

    Dino,

    You can do it like this:

    VB Code:
    1. Dim myForm As Form
    2.         For Each myForm In Me.MdiChildren
    3.             myForm.WindowState = FormWindowState.Minimized
    4.         Next

    Or, if you're using that forms collection we spoke about then you can iterate through the forms, in the collection and set the minimised property:

    VB Code:
    1. Dim myforms As FormsCollection
    2.         Dim myForm As Form
    3.         For Each myForm In myforms
    4.             form.WindowState = FormWindowState.Minimized
    5.         Next
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Minimise all MDI Chill forms .

    Hiyam

    I am using your code on the forms collection...

    I can use the first bit of code, but the second one does not work.

    I have option strict on, is that the problem?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Minimise all MDI Chill forms .

    I've never heard of FormsCollection and a search didn't show me anything either. Perhaps it's a custom class that you and the squirrel talked about at some earlier point in space and time?

  5. #5

    Thread Starter
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Minimise all MDI Chill forms .

    yeah it is a custom class...

    Squirrel gave it to me...
    here it is..

    VB Code:
    1. Option Strict On
    2.  
    3. ''' -----------------------------------------------------------------------------
    4. ''' Project  : AML
    5. ''' Class    : FormsCollection
    6. '''
    7. ''' -----------------------------------------------------------------------------
    8. ''' <summary>
    9. ''' Replicates the forms collection that was inherant to VB
    10. ''' </summary>
    11. ''' <remarks>
    12. ''' </remarks>
    13. ''' <history>
    14. '''     [RIngram]   17/09/2004  Created
    15. ''' </history>
    16. ''' -----------------------------------------------------------------------------
    17. Public Class FormsCollection
    18.     Inherits System.Collections.CollectionBase
    19.  
    20.     ''' -----------------------------------------------------------------------------
    21.     ''' <summary>
    22.     ''' Adds a new item to the forms collection
    23.     ''' </summary>
    24.     ''' <param name="formToAdd">The form to add to the collection</param>
    25.     ''' <remarks>
    26.     ''' If the form count is greater than two then it shows the window menu.  
    27.     ''' This is because the MDI form and the error form stay in memory the entire time so
    28.     ''' a window count of greater than two indicates that the user is likely to want to toggle
    29.     ''' the window about
    30.     ''' </remarks>
    31.     ''' <history>
    32.     '''     [RIngram]   17/09/2004  Created
    33.     ''' </history>
    34.     ''' -----------------------------------------------------------------------------
    35.     Public Sub Add(ByVal formToAdd As Form)
    36.         MyBase.InnerList.Add(formToAdd)
    37.     End Sub
    38.  
    39.     ''' -----------------------------------------------------------------------------
    40.     ''' <summary>
    41.     ''' Removes the selected form from the collection
    42.     ''' </summary>
    43.     ''' <param name="formToRemove"></param>
    44.     ''' <remarks>
    45.     ''' If the form count drops to two or below then hide the window menu
    46.     ''' </remarks>
    47.     ''' <history>
    48.     '''     [RIngram]   17/09/2004  Created
    49.     ''' </history>
    50.     ''' -----------------------------------------------------------------------------
    51.     Public Sub Remove(ByVal formToRemove As Form)
    52.         MyBase.InnerList.Remove(formToRemove)
    53.     End Sub
    54.  
    55.     ''' -----------------------------------------------------------------------------
    56.     ''' <summary>
    57.     ''' Checks to see if the form is in the collection
    58.     ''' </summary>
    59.     ''' <param name="formName">The name of the form to locate</param>
    60.     ''' <returns>The form specified</returns>
    61.     ''' <remarks>
    62.     ''' </remarks>
    63.     ''' <history>
    64.     '''     [RIngram]   17/09/2004  Created
    65.     ''' </history>
    66.     ''' -----------------------------------------------------------------------------
    67.     Public Function IsInCollection(ByVal formName As String) As Form
    68.         Dim item As Form
    69.         Try
    70.             For Each item In list
    71.                 If Not IsNothing(item) Then
    72.                     If item.Name.ToLower = formName.ToLower Then
    73.                         Return CType(item, Form)
    74.                     End If
    75.                 End If
    76.             Next
    77.             'if execution reaches here then the form was not found so return nothing
    78.             Return Nothing
    79.         Catch ex As Exception
    80.             Return Nothing
    81.         Finally
    82.             item = Nothing
    83.         End Try
    84.  
    85.     End Function
    86.  
    87.     ''' -----------------------------------------------------------------------------
    88.     ''' <summary>
    89.     ''' Checks to see if an instance of a form is in a collection
    90.     ''' </summary>
    91.     ''' <param name="formName">The name of the form to look for</param>
    92.     ''' <param name="row">The datarow to match</param>
    93.     ''' <returns>The instance of the form if a match is made</returns>
    94.     ''' <remarks>
    95.     ''' Used when multiple instances of the same form are required.  Identifies a unique instance
    96.     ''' by iterating the forms collection, matching first by name and then by the data row that
    97.     ''' should be stored in each form's tag.  
    98.     ''' Assumes that the record identifier will always be stored in the first column of the record
    99.     ''' </remarks>
    100.     ''' <history>
    101.     '''     [RIngram]   17/09/2004  Created
    102.     ''' </history>
    103.     ''' -----------------------------------------------------------------------------
    104.     Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form
    105.         Dim item As Form
    106.         Dim formRow As DataRow
    107.         Dim counter As Integer
    108.         Try
    109.             'loop through the forms collection
    110.             For Each item In list
    111.                 If item.Name.ToLower = formName.ToLower Then
    112.                     'if the form names match then retrieve the row
    113.                     formRow = CType(item.Tag, DataRow)
    114.                     'if the items in the left most columns match then return the form as the correct item
    115.                     If formRow(0) Is row(0) Then
    116.                         Return item
    117.                     End If
    118.                 End If
    119.             Next
    120.         Catch ex As Exception
    121.             Return Nothing
    122.         Finally
    123.             formRow = Nothing
    124.             item = Nothing
    125.         End Try
    126.     End Function
    127.  
    128.     ''' -----------------------------------------------------------------------------
    129.     ''' <summary>
    130.     ''' Overloaded function.
    131.     ''' </summary>
    132.     ''' <param name="formName">The name of the form to look for</param>
    133.     ''' <param name="id">The ID of the record which is stored in the form's tag as a string</param>
    134.     ''' <returns>The form if found otherwise nothing</returns>
    135.     ''' <remarks>
    136.     ''' </remarks>
    137.     ''' <history>
    138.     '''     [RIngram]   15/03/2005  Created
    139.     ''' </history>
    140.     ''' -----------------------------------------------------------------------------
    141.     Public Function IsInstanceInCollection(ByVal formName As String, ByVal id As String) As Form
    142.         Dim item As Form
    143.         Dim tag As String
    144.         Try
    145.             For Each item In list
    146.                 If item.Name.ToLower = formName.ToLower Then
    147.                     tag = item.Tag.ToString.ToLower
    148.                     If tag.ToLower = id.ToLower Then
    149.                         Return item
    150.                     End If
    151.                 End If
    152.             Next
    153.         Catch ex As Exception
    154.             Return Nothing
    155.         Finally
    156.             item = Nothing
    157.         End Try
    158.     End Function
    159.  
    160.     ''' -----------------------------------------------------------------------------
    161.     ''' <summary>
    162.     ''' Overloaded function.  Checks to see if an instance of a form is in the collection
    163.     ''' </summary>
    164.     ''' <param name="formName">The name of the form to look for eg frmLookupList</param>
    165.     ''' <param name="table">The associated datatable</param>
    166.     ''' <returns>The matched form or nothing if the form is not found</returns>
    167.     ''' <remarks>
    168.     ''' Used when multiple instances of the same form are required.  Identifies a unique instance
    169.     ''' by iterating the forms collection, matching first by name and then by the datatable that
    170.     ''' should be stored in each form's tag.  
    171.     ''' Assumes that the table names will match.
    172.     ''' </remarks>
    173.     ''' <history>
    174.     '''     [RIngram]   20/09/2004  Created
    175.     ''' </history>
    176.     ''' -----------------------------------------------------------------------------
    177.     Public Function IsInstanceInCollection(ByVal formName As String, ByVal table As DataTable) As Form
    178.         Dim item As Form
    179.         Dim formTable As DataTable
    180.         Dim counter As Integer
    181.         Try
    182.             'loop through the forms collection
    183.             For Each item In list
    184.                 If item.Name.ToLower = formName.ToLower Then
    185.                     'if the form names match then retrieve the row
    186.                     formTable = CType(item.Tag, DataTable)
    187.                     'if the items in the left most columns match then return the form as the correct item
    188.                     If formTable.TableName.ToLower = table.TableName.ToLower Then
    189.                         Return item
    190.                     End If
    191.                 End If
    192.             Next
    193.         Catch ex As Exception
    194.             Return Nothing
    195.         Finally
    196.             formTable = Nothing
    197.             item = Nothing
    198.         End Try
    199.     End Function
    200. End Class

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Minimise all MDI Chill forms .

    Then the second snippet of code should be

    VB Code:
    1. Dim myforms As FormsCollection
    2.         Dim myForm As Form
    3.         For Each myForm In myforms
    4.             myForm.WindowState = FormWindowState.Minimized
    5.         Next

  7. #7
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Minimise all MDI Chill forms .

    Yes, it is a custom class from another thread.

    Dino, you should use the reference to the forms collection wherever you created it rather than declaring it locally as the code sample shows.

    I imagine you will have created it as an application level object so rather than using a dim as in the code above, just reference the app level forms collection object you've created.
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

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