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
Printable View
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
Dino,
You can do it like this:
VB Code:
Dim myForm As Form For Each myForm In Me.MdiChildren myForm.WindowState = FormWindowState.Minimized 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:
Dim myforms As FormsCollection Dim myForm As Form For Each myForm In myforms form.WindowState = FormWindowState.Minimized Next
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?
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?
yeah it is a custom class...
Squirrel gave it to me...
here it is..
VB Code:
Option Strict On ''' ----------------------------------------------------------------------------- ''' Project : AML ''' Class : FormsCollection ''' ''' ----------------------------------------------------------------------------- ''' <summary> ''' Replicates the forms collection that was inherant to VB ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [RIngram] 17/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Class FormsCollection Inherits System.Collections.CollectionBase ''' ----------------------------------------------------------------------------- ''' <summary> ''' Adds a new item to the forms collection ''' </summary> ''' <param name="formToAdd">The form to add to the collection</param> ''' <remarks> ''' If the form count is greater than two then it shows the window menu. ''' This is because the MDI form and the error form stay in memory the entire time so ''' a window count of greater than two indicates that the user is likely to want to toggle ''' the window about ''' </remarks> ''' <history> ''' [RIngram] 17/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Sub Add(ByVal formToAdd As Form) MyBase.InnerList.Add(formToAdd) End Sub ''' ----------------------------------------------------------------------------- ''' <summary> ''' Removes the selected form from the collection ''' </summary> ''' <param name="formToRemove"></param> ''' <remarks> ''' If the form count drops to two or below then hide the window menu ''' </remarks> ''' <history> ''' [RIngram] 17/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Sub Remove(ByVal formToRemove As Form) MyBase.InnerList.Remove(formToRemove) End Sub ''' ----------------------------------------------------------------------------- ''' <summary> ''' Checks to see if the form is in the collection ''' </summary> ''' <param name="formName">The name of the form to locate</param> ''' <returns>The form specified</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [RIngram] 17/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Function IsInCollection(ByVal formName As String) As Form Dim item As Form Try For Each item In list If Not IsNothing(item) Then If item.Name.ToLower = formName.ToLower Then Return CType(item, Form) End If End If Next 'if execution reaches here then the form was not found so return nothing Return Nothing Catch ex As Exception Return Nothing Finally item = Nothing End Try End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Checks to see if an instance of a form is in a collection ''' </summary> ''' <param name="formName">The name of the form to look for</param> ''' <param name="row">The datarow to match</param> ''' <returns>The instance of the form if a match is made</returns> ''' <remarks> ''' Used when multiple instances of the same form are required. Identifies a unique instance ''' by iterating the forms collection, matching first by name and then by the data row that ''' should be stored in each form's tag. ''' Assumes that the record identifier will always be stored in the first column of the record ''' </remarks> ''' <history> ''' [RIngram] 17/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Function IsInstanceInCollection(ByVal formName As String, ByVal row As DataRow) As Form Dim item As Form Dim formRow As DataRow Dim counter As Integer Try 'loop through the forms collection For Each item In list If item.Name.ToLower = formName.ToLower Then 'if the form names match then retrieve the row formRow = CType(item.Tag, DataRow) 'if the items in the left most columns match then return the form as the correct item If formRow(0) Is row(0) Then Return item End If End If Next Catch ex As Exception Return Nothing Finally formRow = Nothing item = Nothing End Try End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Overloaded function. ''' </summary> ''' <param name="formName">The name of the form to look for</param> ''' <param name="id">The ID of the record which is stored in the form's tag as a string</param> ''' <returns>The form if found otherwise nothing</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [RIngram] 15/03/2005 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Function IsInstanceInCollection(ByVal formName As String, ByVal id As String) As Form Dim item As Form Dim tag As String Try For Each item In list If item.Name.ToLower = formName.ToLower Then tag = item.Tag.ToString.ToLower If tag.ToLower = id.ToLower Then Return item End If End If Next Catch ex As Exception Return Nothing Finally item = Nothing End Try End Function ''' ----------------------------------------------------------------------------- ''' <summary> ''' Overloaded function. Checks to see if an instance of a form is in the collection ''' </summary> ''' <param name="formName">The name of the form to look for eg frmLookupList</param> ''' <param name="table">The associated datatable</param> ''' <returns>The matched form or nothing if the form is not found</returns> ''' <remarks> ''' Used when multiple instances of the same form are required. Identifies a unique instance ''' by iterating the forms collection, matching first by name and then by the datatable that ''' should be stored in each form's tag. ''' Assumes that the table names will match. ''' </remarks> ''' <history> ''' [RIngram] 20/09/2004 Created ''' </history> ''' ----------------------------------------------------------------------------- Public Function IsInstanceInCollection(ByVal formName As String, ByVal table As DataTable) As Form Dim item As Form Dim formTable As DataTable Dim counter As Integer Try 'loop through the forms collection For Each item In list If item.Name.ToLower = formName.ToLower Then 'if the form names match then retrieve the row formTable = CType(item.Tag, DataTable) 'if the items in the left most columns match then return the form as the correct item If formTable.TableName.ToLower = table.TableName.ToLower Then Return item End If End If Next Catch ex As Exception Return Nothing Finally formTable = Nothing item = Nothing End Try End Function End Class
Then the second snippet of code should be
VB Code:
Dim myforms As FormsCollection Dim myForm As Form For Each myForm In myforms myForm.WindowState = FormWindowState.Minimized Next
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.