To best illustrate my point, I'll display a whole lot of code that declares classes, has class constructors, handles global form and component skinning and deals with the user clicking the 'x' close button on a form, in Visual Basic 2008. If you have the Developer's Express Enterprise edition, you should be able to use the code exactly as you see it. Aside from getting eyestrain, I hope this will help you to see that the constructor is a separate entity from the form load event.
And, if you see any code you would like to use in your own programs, please help yourself!
Russ
Here goes............................
#Region " Options "
Option Explicit On
Option Strict On
Option Infer Off
#End Region ' Options
#Region " Imports "
#Region " Windows "
Imports System
Imports System.IO
Imports System.Text
Imports System.Data
Imports System.DateTime
Imports System.Data.OleDb
Imports System.Diagnostics
Imports System.IO.Directory
Imports System.Globalization
Imports System.Data.SqlClient
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports System.Text.RegularExpressions
#End Region ' Windows
#Region " DevExpress "
Imports DevExpress.XtraEditors
Imports DevExpress.Utils
' I usually load the whole skins library!
Region " Developer's Express Skins "
Imports DevExpress.Skins
Imports DevExpress.Skins.Skin
Imports DevExpress.Skins.TabSkins
Imports DevExpress.Skins.BarSkins
Imports DevExpress.Skins.FormSkins
Imports DevExpress.Skins.GridSkins
Imports DevExpress.Skins.VGridSkins
Imports DevExpress.Skins.RibbonSkins
Imports DevExpress.Skins.NavBarSkins
Imports DevExpress.Skins.CommonSkins
Imports DevExpress.Skins.SkinManager
Imports DevExpress.Skins.EditorsSkins
Imports DevExpress.Skins.DockingSkins
Imports DevExpress.Skins.NavPaneSkins
Imports DevExpress.Skins.ReportsSkins
Imports DevExpress.Skins.SchedulerSkins
Imports DevExpress.Skins.TabSkinProperties
Imports DevExpress.Skins.SkinManagerHelper
#End Region ' Developer's Express Skins
#End Region ' DevExpress
#End Region ' Imports
' In the global declarations module, place:
Friend Const FRMTITLE As String = " Trojans Training Schedule: "
Friend Const PROB As String = "Problem in " ' use in error message boxes
#Region " MessageBox Buttons "
Friend Const MBBOK As MessageBoxButtons = MessageBoxButtons.OK
Friend Const MBBYN As MessageBoxButtons = MessageBoxButtons.YesNo
Friend Const MBBOC As MessageBoxButtons = MessageBoxButtons.OKCancel
Friend Const MBBRC As MessageBoxButtons = MessageBoxButtons.RetryCancel
Friend Const MBBYC As MessageBoxButtons = MessageBoxButtons.YesNoCancel
Friend Const MBBAR As MessageBoxButtons = MessageBoxButtons.AbortRetryIgnore
#End Region ' MessageBox Buttons
#Region " Windows Forms Dialogs Results "
Friend Const WFDNO As Windows.Forms.DialogResult = DialogResult.No
Friend Const WFDYES As Windows.Forms.DialogResult = DialogResult.Yes
Friend Const WFDOK As Windows.Forms.DialogResult = DialogResult.OK
Friend Const WFDRETRY As Windows.Forms.DialogResult = DialogResult.Retry
Friend Const WFDNONE As Windows.Forms.DialogResult = DialogResult.None
Friend Const WFDABORT As Windows.Forms.DialogResult = DialogResult.Abort
Friend Const WFDIGNORE As Windows.Forms.DialogResult = DialogResult.Ignore
Friend Const WFDCANCEL As Windows.Forms.DialogResult = DialogResult.Cancel
#End Region ' Windows Forms Dialogs Results
#Region " MessageBox Icons "
Friend Const MBISTOP As MessageBoxIcon = MessageBoxIcon.Stop
Friend Const MBIHAND As MessageBoxIcon = MessageBoxIcon.Hand
Friend Const MBINONE As MessageBoxIcon = MessageBoxIcon.None
Friend Const MBIEROR As MessageBoxIcon = MessageBoxIcon.Error
Friend Const MBIWARN As MessageBoxIcon = MessageBoxIcon.Warning
Friend Const MBIASTE As MessageBoxIcon = MessageBoxIcon.Asterisk
Friend Const MBIQUES As MessageBoxIcon = MessageBoxIcon.Question
Friend Const MBIEXCL As MessageBoxIcon = MessageBoxIcon.Exclamation
Friend Const MBIINFO As MessageBoxIcon = MessageBoxIcon.Information
#End Region ' MessageBox Icons
#Region " MessageBox Default Buttons "
Friend Const MBDB1 As MessageBoxDefaultButton = MessageBoxDefaultButton.Button1
Friend Const MBDYES As MessageBoxDefaultButton = MBDB1
Friend Const MBDB2 As MessageBoxDefaultButton = MessageBoxDefaultButton.Button2
Friend Const MBDNO As MessageBoxDefaultButton = MBDB2
Friend Const MBDB3 As MessageBoxDefaultButton = MessageBoxDefaultButton.Button3
#End Region ' MessageBox Default Buttons
' Developer's Express screen themes (skins) it will be used with 'mainTheme' variable
' to allow the user to change the theme to any listed below, no matter how many forms
' and components...
'
#Region "Screen Themes"
Friend Const SCRCARA As String = "Caramel"
Friend Const SCRMONE As String = "Money Twins"
Friend Const SCRLILI As String = "Lilian"
Friend Const SCRASPH As String = "The Asphalt World"
Friend Const SCRIMAG As String = "iMaginary"
Friend Const SCRBLAC As String = "Black"
Friend Const SCRBLUE As String = "Blue"
Friend Const SCRCOFF As String = "Coffee"
Friend Const SCRLIQS As String = "Liquid Sky"
Friend Const SCRLLIQ As String = "London Liquid Sky"
Friend Const SCRGLAS As String = "Glass Oceans"
Friend Const SCRSTAR As String = "Stardust"
Friend Const SCRX08B As String = "Xmas 2008 Blue"
Friend Const SCRVALN As String = "Valentine"
Friend Const SCRMCSK As String = "McSkin"
Friend Const SCRO7BU As String = "Office 2007 Blue"
Friend Const SCRO7BL As String = "Office 2007 Black"
Friend Const SCRO7SI As String = "Office 2007 Silver"
Friend Const SCRO7GR As String = "Office 2007 Green"
Friend Const SCRO7PI As String = "Office 2007 Pink"
#End Region ' Screen Themes
Friend Const PROB As String = "Problem in " ' used in Try-Catch-End Try blocks
Friend isClosing As Boolean = False ' used to deal with Form_Closing Event
Friend emptStr As String = String.Empty ' empty string, shorter than String.Empty
Friend mainTheme As String = SCRMONE ' set the theme for skinning - Money Twins
'
' with this variable, you can allow the user to change to the skin of their choice
' see EnableSkins() below
'end global declarations ---------------------------------------------------------
'---------------------------------------------------------------------------------
' Sub Main() with an easy way to prepare to globally set skinning
'---------------------------------------------------------------------------------
Friend Class Program
Private Sub New() ' provide a constructor
End Sub
' use Sub Main() to begin the application ----------------------------------------
<STAThread()> _
Shared Sub Main()
DevExpress.Skins.SkinManager.EnableFormSkins()
DevExpress.UserSkins.BonusSkins.Register()
DevExpress.UserSkins.OfficeSkins.Register()
DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = mainTheme
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(mainTheme)
SetCompatibleTextRendering()
Application.EnableVisualStyles()
' Please note: SetCompatibleTextRendering() must be called before any form is loaded
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New thisForm())
End Sub
End Class ' end of class Program with Sub Main() embedded inside
'---------------------------------------------------------------------------------
' Here is the thisForm class called above in Sub Main()
' use this code if you have Developer's Express forms
Public Class thisForm : Inherits XtraForm
' put your constructor just below the class declaration
'
Public Sub New()
'
' Required for Windows Form Designer support
'
InitializeComponent()
'
' put any other custom declarations here
'
End Sub
' next, move on to the form load event
'
'---------------------------------------------------------------------------------
' Form_Load - Please note: EnableSkins() should be called when each form loads.
'---------------------------------------------------------------------------------
Private Sub FormLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
EnableSkins() ' set skinning for the form
Me.Text = FRMTITLE & "thisForm"
isClosing = False ' part of form closing strategy
KeepFormSize(Me) ' keep form size static - if you wish
End Sub
'---------------------------------------------------------------------------------
Friend Sub SetCompatibleTextRendering()
Try
Application.SetCompatibleTextRenderingDefault(False)
Catch ex As Exception
XtraMessageBox.Show(ex.Message, PROB & "SetCompatibleTextRendering", MBBOK, MBISTOP)
End Try
End Sub
'---------------------------------------------------------------------------------
Friend Sub EnableSkins()
Try
DevExpress.Skins.SkinManager.EnableFormSkins()
DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged()
DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = mainTheme
DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(mainTheme)
Application.EnableVisualStyles()
Catch ex As Exception
XtraMessageBox.Show(ex.Message, PROB & "EnableSkins", MBBOK, MBIWARN)
End Try
End Sub
'---------------------------------------------------------------------------------
Friend Sub KeepFormSize(ByVal formName As Form)
Try
formName.MinimumSize = formName.Size ' cannot be sized smaller
formName.MinimizeBox = False ' show no minimize box
formName.MaximumSize = formName.Size ' cannot be sized larger
formName.MaximizeBox = False ' show no maximize box
formName.StartPosition = FormStartPosition.CenterScreen ' draw in middle of the screen
Catch ex As Exception
XtraMessageBox.Show(ex.Message, PROB & "KeepFormSize", MBBOK, MBISTOP)
End Try
End Sub
'---------------------------------------------------------------------------------
' For the FormClosing strategy: In the Form_Closing, place:
'---------------------------------------------------------------------------------
Private Sub thisForm_FormClosing(ByVal sender As Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles Me.FormClosing
Try
If isClosing = True Then ' the menu exit item was clicked
' user answered question with yes
' in the menu or button exit command
' Do any pre-close processing
e.Cancel = Nothing ' set the cancel flag to NULL
Application.Exit() ' move out
Else ' isClosing = False from file exit click
' user clicked x on right of form
' need to show the exit question
If XtraMessageBox.Show("Close the Form?", FRMEXIT, MBBYN, MBIQUES) = WFDYES Then
' Do any pre-close processing
e.Cancel = Nothing ' set the cancel flag to NULL
Application.Exit() ' move out
Else ' the user doesn't want to exit
e.Cancel = True ' set the cancel flag to true
End If ' End If XtraMessageBox.Show(...
End If ' End If isClosing = True
Catch ex As Exception
XtraMessageBox.Show(ex.Message, PROB & "thisForm_FormClosing", MBBOK, MBIWARN)
End Try
End Sub
'---------------------------------------------------------------------------------
' For the FormClosing strategy: In the menu exit or exit button click event, place:
'---------------------------------------------------------------------------------
Private Sub mnuFileExit_ItemClick(ByVal sender As System.Object, _
ByVal e As DevExpress.XtraBars.ItemClickEventArgs) _
Handles mnuFileExit.ItemClick
Try
' ask the user the exit question when menu item or button is clicked.
'
If XtraMessageBox.Show("Close the Attendee Data Entry Form?", FRMEXIT, MBBYN, MBIQUES) _
= WFDYES Then
isClosing = True ' they said 'yes' they want to exit
Me.Close() ' start the ball rolling
' this will activate the first isClosing = True
' in the Form_Closing event
Else ' the user doesn't want to exit
isClosing = False ' set the global exit flag to False
End If ' End If XtraMessageBox.Show(...
Catch ex As Exception
XtraMessageBox.Show(ex.Message, PROB & "mnuFileExit_Click", MBBOK, MBIWARN)
End Try
End Sub