Windows Forms Collection

  • Thread starter
  • Start date



how can we get the forms collection object in a class as we did in VB 6. as
if we need to do same type of work in different forms we just make a common
function and pass form object into it and do our work as below:

we have a function lets supppose :
Function ChangeBackgroundColor(ByVal f as Form)
End Function

How can we do this in VB.NET??

Regards and Thanks if someone help me in this.



Christopher Kimbell


I am not a big VB programmer, so I am not sure what the "collection object
in a class" is.
In response to your sample code, the Form object in .NET has a BackColor
property that you can set, so you don't need a function to do it.

One thing you have in .NET that you didn't in VB, is inheritance. If there
is common code you want to make available in several of your forms, you can
create a form that inherits from the System.Windows.Forms.Form, lets call it
MyBaseForm. In this form you can add new properties, methods, events and GUI
elements. Your forms can then inherit from MyBaseForm and get all the new
stuff, use the "Add inherited form" when adding new forms in Visual Studio.

If you have visual elements like buttons on your base form, these must be
made public in order to move them around on inherited forms, if not, they
are locked to the position they have in the base form.




Steve Moores

Try something like this:

Public Function ChangeBackgroundColor(ByRef f as System.Windows.Forms.Form)
f.BackColor = ....
End Function

Just call it from any form using ChangeBackgroundColor(Me)

Should work, no? Pretty much the same here as VB6, just ensure it's passed

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question