IT Hardwares

eg: UK or Brides UK or Classical Art or Buy Music or Spirituality
 
eg: UK or Brides UK or Classical Art or Buy Music or Spirituality
 
Business & Money
Technology
Women
Health
Education
Family
Travel
Cars
Entertainment
SD Editorials
Online Guide and article directory site.
Foodeditorials.com
Over 15,000 recipes & editorials on food.
Lyricadvisor.com
Get 100,000 Lyric & Albums.
  • Business & Money
    • A Guide to Business
    • Guide to Finance
    • Ideas for Marketing
    • Legal Guide
    • Guide to Insurance
    • Lettre De Motivation
    • Guide to the Stock Market
    • Human Resource Career
    • Sales Marketing
    • Forex & Trading
    • Advertising & Marketing
    • Startup Guide
  • Technology
    • Guide to Technology
    • Cell Phones
    • Computer Software
    • IT Hardwares
    • Internet
    • Online Security
    • Cameras
    • Search Engine Optimization
    • Science & Technology
  • Women
    • Guide to Women
    • Relationship Advice
    • Marriage
    • Jewelry
    • Pregnancy
    • Fashion Style
    • Divorce Guide
    • Wedding Guide
    • Dating Guide
    • Natural Beauty
  • Health
    • Guide to Health
    • Guide to Medical
    • Plastic Surgery
    • Weight Loss
    • Sports
    • Body Wellness
    • Cancer Treatment
    • Common Illness
    • Health & Lifestyle
  • Education
    • Military Service
    • Politics and Policy
    • Arts & Humanities
    • Education and Teaching
    • Learn Languages
    • Colleges & Universities
  • Family
    • Quality Home Improvement
    • Hobbies and Interests
    • Family Guide to
    • Pet Guide
    • Loans Guide
    • Credit Cards
    • Gardening Guide
    • Home Security
    • Real Estate
    • Home Decor
    • Gift & Present
  • Travel
    • The Travel Guide
    • Adventure Travel
    • Cruise Ships
    • Beach Holiday
    • Travel Accommodation
    • Holiday Destinations
  • Cars
    • Information on Cars
    • Traffic Violations
    • Auto Insurance
    • Trailers
    • Sport Cars
    • The Bikes
  • Entertainment
    • Entertainment Guide
    • World Music
    • Photo & Video
    • Television & Games

Vb Net Dynamic Controls

    View: 
Let's assume that we want to load several MDI child forms, allowing each of them to be loaded only once, and of course to know when one of the child forms is closed. Since we have several forms to load we would like to use the AddHandler and RemoveHandler keywords so we can be flexible and write the minimal code we can.



Let's get dirty.

1. In each MDI child form we have to declare a public event.

Public Event FormClosed(ByVal f As Form)

2. In each MDI child form we have to use the Form_Closed method which handles the MyBase.Closed class and raise the FormClosed event.

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) _

Handles MyBase.Closed

RaiseEvent FormClosed(Me)

End Sub


3. On our MDI form we need to declare two member variables. The first's of type Form and the second's type is ArrayList.

Private m_f(0) as Form

Private m_sLoadedChildForms As New ArrayList


4. We need to implement a method the will search the MDI child forms that are loaded. We'll also use this method when we unload the MDI child forms.

Private Function SearchChildForm(ByVal strSearchForm As String, _Optional ByVal idxEventHandler As Long = -1) As Long

Dim i As Long = 0

For i = 0 To m_sLoadedForms.Count - 1

If m_sLoadedForms.Item(i) = strSearchForm Then

Dim j As Long = 0

For j = m_f.GetLowerBound(0) To m_f.GetUpperBound(0)

If m_f(j).Name = strSearchForm Then idxEventHandler = j

Next j

Return i

End If

Next

Return -1

End Function


5. We need to implement a method to load the mdi child forms and use the SearchChildForm method in order not to load the same mdi child form second time.

Private Sub LoadChildForms(ByVal f As Form)

If m_f.GetUpperBound(0) > 0 Then

ReDim Preserve m_f(m_f.GetUpperBound(0) + 1)

End If

m_f(m_f.GetUpperBound(0)) = f I

f Not SearchChildForm(m_f(m_f.GetUpperBound(0)).Name()) >= 0 Then

m_f(m_f.GetUpperBound(0)).MdiParent = Me

AddHandler m_f(m_f.GetUpperBound(0)).Closed, _

AddressOf UnloadChildForm

m_f(m_f.GetUpperBound(0)).Show()

m_sLoadedChildForms.Add(m_f(m_f.GetUpperBound(0)).Name)

Else

If m_f.GetUpperBound(0) > 0 Then

ReDim Preserve m_f(m_f.GetUpperBound(0) - 1)

End If

End If

End Sub


6. At last we need to implement a method to take out our mdi child form from the array list so we can load it again if we want.

Private Sub UnloadForm(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim i As Long

Dim s As String = sender.GetType().Name

Dim IndexForEventHandler = -1

i = SearchChildForm(s, IndexForEventHandler)

If i >= 0 Then m_sLoadedForms.RemoveAt(i)

If IndexForEventHandler >= 0 Then

RemoveHandler m_f(IndexForEventHandler).Closed, AddressOf UnloadForm

m_f(IndexForEventHandler) = Nothing

End If

End Sub
More Articles from
Computer Hardware Guide Pg335
Affordable Web Site Host
Automatic Search Engine Submission
Designer Bags And Shoes
Finding Target Heart Rate
Finding The Right Shoe
Finding Your Mac Address
Firewire Hard Disk Enclosure
Free Internet For Sony Ericsson
Free Web Host Ftp
High Page Rank Sites
It Cost Benefit Analysis
Make A Photography Book
Phones With Gps Navigation
Place To Buy Electronics
Printer Ink Cartridges Refills
Property Rental Management Software
Remove Antivirus Xp 2008
Steps In Data Analysis
Wholesale Products To Sell Online
Why Computer Slow Down
» More on
Computer Hardware Guide
  • Related Articles
  • Author
  • Most Popular
•A Company Net Worth, by Allan Smithz
•Ab Infi Net Internet Banking, by John Eberhard
•Activex Controls In Vb, by Arvind Singh
•Ado And Ado Net, by Adam Sturo
•Ado Net Connection Pooling, by Adam Sturo
Thomas Kaloyani has sinced written about articles on various topics from Estate Planning, Computers and The Internet. . Thomas Kaloyani's top article generates over 590 views. to your Favourites.
Alzheimer's Plaques And Tangles
However, if we exercise our minds and bodies and provide them with restorative and protective phytonutrients we have a far greater chance of retaining sharp, active brains well into our senior years ...
 
A Guide to Business | Guide to Technology | Guide to Women | Guide to Health | Family Guide to | Travel & Vacations | Information on Cars

EditorialToday IT Hardwares has 2 sub sections. Such as Computer Guide and Hardware. With over 20,000 authors and writers, we are a well known online resource and editorial services site in United Kingdom, Canada & America . Here, we cover all the major topics from self help guide to A Guide to Business, Guide to Finance, Ideas for Marketing, Legal Guide, Lettre De Motivation, Guide to Insurance, Guide to Health, Guide to Medical, Military Service, Guide to Women, Pet Guide, Politics and Policy , Guide to Technology, The Travel Guide, Information on Cars, Entertainment Guide, Family Guide to, Hobbies and Interests, Quality Home Improvement, Arts & Humanities and many more.
About Editorial Today | Contact Us | Terms of Use | Submit an Article | Our Authors