Module: VB_Forms in Category Microsoft Visual Basic 6 : Forms from Total Visual SourceBook

Routines to enhance the behavior and features of forms in Visual Basic 6 (VB6).

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modVB_Forms module.
CenterForm Procedure Center the form on the screen. Generally this function is called from the Load event of a form. See also the CenterForm method of the CFormPos class.
DisableCloseMenu Procedure Gray out the Close item on the form's system menu. Since the user can no longer close the form with the system menu or the 'X' close button on the title bar, your application must provide another way to close the form.
FormOnTop Procedure Set the form's style to be always on top or remove the always on top style.
GetFormNamed Procedure Retrieve a reference to form based on a string name. This procedure may be used to assign a specific loaded form that is already in the Forms collection to a form variable.
LoadFormByName Procedure Load a form by using a string variable with the name of the form to avoid hard-coding form references. In some table-driven applications, it may be desirable to determine the name of the form to load based on a passed string. Normally you specify the name of the form explicitly in VB6 code when using the Load procedure or Show method of a form. This procedure uses the Add method of the VB6 Forms collection to add a form. The new form is also returned as a return value of the function.
MakeTransparent Procedure Set the form's style to be transparent. Objects placed on the form are still visible and will receive mouse and keyboard events. This call should be made before the form is shown, for example in the Load event.
' Example of modVB_Forms
'
' To try this example, do the following:
' 1. Create a new form named "Form1" and make it the startup form
' 2. Create a command button 'cmdToggleOnTop'
' 3. Create a command button 'cmdClose'
' 4. Create a command button 'cmdTransparent'
' 5. Create a command button 'cmdFormName'
' 6. Create a new form named "Form2"
' 7. Create a new form named "Form3"
' 8. Paste all the code from this example to the new form's module.

Private Sub Form_Load()

  cmdToggleOnTop.Caption = "Toggle On Top"
  cmdClose.Caption = "Close"
  cmdTransparent.Caption = "Make Transparent"
  cmdFormName.Caption = "Form by Name"

  ' Example of CenterForm
  CenterForm Me

  ' Example of DisableCloseMenu
  ' Since this menu disables the Close menu item, you'll have to close the form with the 'cmdClose' button
  DisableCloseMenu Me

End Sub

Private Sub cmdToggleOnTop_Click()
  Static fState As Boolean
  fState = Not fState

  ' Example of FormOnTop
  ' Switch the form back and forth from having the AlwaysOnTop attribute to not having it
  FormOnTop Me, fState

End Sub

Private Sub cmdTransparent_Click()
  ' Example of MakeTransparent

  ' Normally this call is made before the form is shown.
  ' In this example the form is hidden, altered, and then made visible again to simulate this
  Me.Visible = False
  MakeTransparent Me
  Me.Visible = True

End Sub

Private Sub cmdFormName_Click()

  Dim frm2 As Form
  Dim frm3 As Form

  ' Example of LoadFormByName
  Set frm2 = LoadFormByName("form2")
  frm2.Caption = "Form 2 Loaded by Name"
  frm2.Visible = True

  ' Example of GetFormName
  Load Form3
  Set frm3 = GetFormNamed("form3")
  frm3.Caption = "Form 3, Referenced by Name"
  frm3.Visible = True

End Sub

Private Sub cmdClose_Click()
  Dim intCount As Integer
  For intCount = Forms.Count - 1 To 0 Step -1
    If Not Forms(intCount) Is Me Then
      Unload Forms(intCount)
    End If
  Next intCount

  Unload Me

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS