FORM array!

xiaoxiao2021-03-06  21

1. Create a Form array (array of controls)

Public Class FormsCollection

Inherits CollectionBase

Public Shadows Function Add (Byval FormObject As Form) AS Form MyBase.List.Add (FormObject) Return FormObject

END FUNCTION

Public Shadows Sub Remove (Byval FormObject As Form) MyBase.List.Remove (FormObject)

End Sub End Class

2. Define an array instance in the module

Module Module1

Public Forms as FormsCollection Sub

Main () forms = new formscollection () Application.run (New Form1 ())

End Sub

End module

3. Use arrays in the program (in Form1)

Public Sub new () mybase.new ()

'This Call is Required by The Windows Form Designer. InitializationComponent ()' add anyinitization after the initializecomponent () Call.

Forms.Add (me)

End Sub

Protected Overloads Overrides Sub Dispose (byval disposing as boolean) if disposing the

IF not (Components Is Nothing) THEN

Components.dispose ()

END IF

END IF

Mybase.dispose (Disposing)

Forms.Remove (ME)

End Sub

A button in Form1 Click on the event:

DIM Loopform as Form

DIM Getform as Form_2

For Each Loopform in Forms

If loopform.name = "form

2 "Then 'begins to determine if the instance of form2 is created

Messagebox.show ("already existing")

Getform = loopform

EXIT for

END IF

NEXT

转载请注明原文地址:https://www.9cbs.com/read-43130.html

New Post(0)