Hi,
I thought Id post back an alternative solution that ive figured out.
Let me know your thoughts and improvements on this approach.
What ive done, is modified my Dialog form into a class, and I declare all my components as public, and those that handle events, such as my textboxes and buttons as WithEvents in that class.
Then, when I would want to open that dialog form, i assign the components that are declared from the class into my Panel on my main form, so that they appear nice and neat within that panel.
When something happens with that Panel, such as clicking a button, or typing the text into the textbox, the original class still picks up the event, and it can be handled there, rather than trying to add hundreds of components into the main form.
Below is a snippet of the code i used.
within the main form
Dim myFrmSearchFile_Key As New SearchFile_Key_InitializeComponents()
Sub SearchFile_Key()
Me.Panel_DialogArea.Controls.AddRange(New System.Windows.Forms.Control() {myFrmSearchFile_Key.lbFileFolderNo, myFrmSearchFile_Key.lbPartNo, myFrmSearchFile_Key.tbInputFileFolderNo, myFrmSearchFile_Key.tbInputPartNo, myFrmSearchFile_Key.BOTHERSDataGrid_Files})
End Sub
within the class
Public WithEvents lbFileFolderNo As New System.Windows.Forms.Label()
Public lbPartNo = New System.Windows.Forms.Label()
Public WithEvents tbInputFileFolderNo As New System.Windows.Forms.TextBox()
Public WithEvents tbInputPartNo as New System.Windows.Forms.TextBox()
Public BOTHERSDataGrid_Files = New System.Windows.Forms.DataGrid()
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
lbFileFolderNo
lbFileFolderNo.ImageAlign = System.Drawing.ContentAlignment.BottomRight
lbFileFolderNo.Location = New System.Drawing.Point(8, 24)
lbFileFolderNo.Name = "lbFileFolderNo"
lbFileFolderNo.Size = New System.Drawing.Size(80, 16)
lbFileFolderNo.TabIndex = 0
lbFileFolderNo.Text = "File Folder No:"
lbFileFolderNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
lbPartNo
lbPartNo.ImageAlign = System.Drawing.ContentAlignment.BottomRight
lbPartNo.Location = New System.Drawing.Point(24, 48)
lbPartNo.Name = "lbPartNo"
lbPartNo.Size = New System.Drawing.Size(64, 16)
lbPartNo.TabIndex = 1
lbPartNo.Text = "Part No:"
lbPartNo.TextAlign = System.Drawing.ContentAlignment.MiddleRight
tbInputFileFolderNo
tbInputFileFolderNo.Location = New System.Drawing.Point(96, 24)
tbInputFileFolderNo.Name = "tbInputFileFolderNo"
tbInputFileFolderNo.Size = New System.Drawing.Size(96, 20)
tbInputFileFolderNo.TabIndex = 2
tbInputFileFolderNo.Text = ""
tbInputPartNo
tbInputPartNo.Location = New System.Drawing.Point(96, 48)
tbInputPartNo.Name = "tbInputPartNo"
tbInputPartNo.Size = New System.Drawing.Size(96, 20)
tbInputPartNo.TabIndex = 3
tbInputPartNo.Text = ""
BOTHERSDataGrid_Files
CType(BOTHERSDataGrid_Files, System.ComponentModel.ISupportInitialize).BeginInit()
BOTHERSDataGrid_Files.AlternatingBackColor = System.Drawing.Color.Cornsilk
BOTHERSDataGrid_Files.BackgroundColor = System.Drawing.Color.Azure
BOTHERSDataGrid_Files.CaptionBackColor = System.Drawing.Color.RoyalBlue
BOTHERSDataGrid_Files.CaptionForeColor = System.Drawing.Color.White
BOTHERSDataGrid_Files.CaptionText = "Files List ..."
BOTHERSDataGrid_Files.DataMember = ""
BOTHERSDataGrid_Files.HeaderForeColor = System.Drawing.SystemColors.ControlText
BOTHERSDataGrid_Files.Location = New System.Drawing.Point(8, 80)
BOTHERSDataGrid_Files.Name = "BOTHERSDataGrid_Files"
BOTHERSDataGrid_Files.Size = New System.Drawing.Size(312, 184)
BOTHERSDataGrid_Files.TabIndex = 4
End Sub
NB, even though the textbox appears to be a part of the main form, this class still picks up this
event when the text is changed in it!
Private Sub tbInputFileFolderNo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbInputFileFolderNo.TextChanged
aliasBothersConnect.BOTHERS_Connect()
BOTHERS_DataDisplay_Files()
aliasBothersConnect.BOTHERS_Close()
BOTHERSDataGrid_Files.ReadOnly = True
End Sub
Let me know what you think??