I'm working on a project in VB.net (VS19) where various data gets imported into an Access database. I have 9 import forms and they all look similar, a datagridview with 4 buttons: Update, Import From Access, Import From Excel, and Cancel.
The datagridview (DGV) is so the user can see the data before it goes into the database.
I got smart and instead of creating 9 forms manually, I decided to build them with a class. The only difference in the forms is the headers in the DGV. So I built one in the designer and used that to guide my InputForm Class. However, when I go to run this, it garbles the buttons. Here is the Form Code: '''
Private Sub formInput_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.btUpdate = New System.Windows.Forms.Button()
Me.btImportAccessFile = New System.Windows.Forms.Button()
Me.btImportExcelFile = New System.Windows.Forms.Button()
Me.btCancel = New System.Windows.Forms.Button()
CType(Me.dgvImportData, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'dgvImportData
'
Me.dgvImportData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
Me.dgvImportData.Location = New System.Drawing.Point(12, 35)
Me.dgvImportData.Name = "dgvImportData"
Me.dgvImportData.Size = New System.Drawing.Size(1446, 882)
Me.dgvImportData.TabIndex = 0
'
'Update Button
'
Me.btUpdate.Location = New System.Drawing.Point(12, 8)
Me.btUpdate.Name = "btUpdate"
Me.btUpdate.Size = New System.Drawing.Size(144, 21)
Me.btUpdate.TabIndex = 1
Me.btUpdate.Text = "Update"
Me.btUpdate.UseVisualStyleBackColor = True
'
'Import Access Button
'
Me.btImportAccessFile.Location = New Point(btUpdate.Left + 150, 8)
Me.btImportAccessFile.Name = "btImportAccessFile"
Me.btImportAccessFile.Size = New System.Drawing.Size(144, 21)
Me.btImportAccessFile.TabIndex = 2
Me.btImportAccessFile.Text = "Import Access File..."
Me.btImportAccessFile.UseVisualStyleBackColor = True
'
'Import Excel button
'
Me.btImportAccessFile.Location = New Point(btImportAccessFile.Left + 150, 8)
Me.btImportAccessFile.Name = "btImportExcelFile"
Me.btImportAccessFile.Size = New System.Drawing.Size(144, 21)
Me.btImportAccessFile.TabIndex = 3
Me.btImportExcelFile.Text = "Import Excel File..."
Me.btImportAccessFile.UseVisualStyleBackColor = True
'
'Cancel Button
'
Me.btImportAccessFile.Location = New System.Drawing.Point(btImportExcelFile.Left + 150, 8)
Me.btImportAccessFile.Name = "btCancel"
Me.btImportAccessFile.Size = New System.Drawing.Size(144, 21)
Me.btImportAccessFile.TabIndex = 4
Me.btCancel.Text = "Cancel"
Me.btImportAccessFile.UseVisualStyleBackColor = True
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(1470, 929)
Me.Controls.Add(Me.btUpdate)
Me.Controls.Add(Me.btImportAccessFile)
Me.Controls.Add(Me.btImportExcelFile)
Me.Controls.Add(Me.btCancel)
Me.Controls.Add(Me.dgvImportData)
Me.Name = "formInput"
Me.Text = "Import Window"
CType(Me.dgvImportData, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
'''
It is called in the main form by a button click (different buttons have different header names):
'''
Private Sub btImpRtC_Click(sender As Object, e As EventArgs) Handles btImpRtC.Click
Dim inpForm = New formINPUT()
inpForm.SetupDGV("Heading A", "Heading B", "Heading C")
inpForm.Show()
End Sub
'''
The third and fourth buttons are jumbled and the first two buttons are running into one another. Everything looks ok in the manually designed forms and the placement values are based on that. The DGV looks fine and updates depending on what I name the headers. Is there a setting I'm missing that should be in a code built form that is inherent in a designer built form?