|
-
Mar 27th, 2009, 10:44 AM
#1
Thread Starter
Fanatic Member
Dynamically Adding User Control problem
VS 2008
I had a form that had some panels on it. Each panel was basically a different report. Because of speed issues and the need for these "reports" to be accessed elsewhere, I created a user control out of each panel. Each panel consists of a grid and then some buttons under the grid.
I created a blank form to hold the dynamically added user controls. I add the user control to the form like this(paraphrased):
Dim f As New frmUserControlHolder
Dim usrCtrl As UserControl = Nothing
Select Case Type
Case UserControlType.IncomeStatement
usrCtrl = New usrCtlIncomeStatement
Case UserControlType.InventoryValuation
usrCtrl = New usrCtlInventoryValuation
End Select
f.Size = New System.Drawing.Size(New System.Drawing.Point(usrCtrl.Size.Width + 8, usrCtrl.Size.Height + 34))
usrCtrl.Location = New System.Drawing.Point(0, 0)
usrCtrl.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
.Controls.Add(usrCtrl)
.Show()
This all works great. Not a single problem. However, back to the form from which these user controls were created. These "reports" still need to be accessed in their original location. So, I'm trying to dynamically add them to the old form when they are requested. The old form is an mdiChild. The main difference is that when adding them here, I'm resizing the user control, not the form that is holding it. This is what that code looks like(paraphrased, again):
Dim usrCtrl As UserControl = Nothing
usrCtrl = New usrCtlTimeRecords
usrCtrl.Size = New System.Drawing.Size(New System.Drawing.Point(Me.Size.Width - 23, Me.Size.Height - 100))
usrCtrl.Location = New System.Drawing.Point(8, 56)
usrCtrl.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
Me.Controls.Add(usrCtrl)
It adds it, however, the grid, which is on every user control, seems to expand and it is covering up the buttons below it. I've confirmed this by manually moving one of the buttons to a higher location. Even when I make the holder form huge and remove any resizing or location changing code, still the grid expands. I even turned off anchoring in the user control of the grid and the panel which holds the grid. That didn't fix the problem either. Is there anything simple which I'm leaving out?
Thanks
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|