My application is designed on Ptracker and uses WinPart. My mainform is using the following routines to load the winpart control after the menu is item is selected:
Private Sub chosenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim currentAssembly As Assembly = Assembly.GetAssembly(GetType(MainForm))
Dim mi As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem)
Dim classToInstantiate As String = "MyAppWin." + DirectCast(mi.Tag, String)
Dim selectedForm As System.Object = currentAssembly.CreateInstance(classToInstantiate)
ShowSelectedForm(DirectCast(selectedForm, WinPart))
End Sub
Public Sub ShowSelectedForm(ByVal formToLoad As WinPart)
' see if this form is already loaded
For Each ctl As Control In MainFormPanel.Controls
If TypeOf ctl Is WinPart Then
If formToLoad.GetIdValue().Equals(DirectCast(ctl, WinPart).GetIdValue()) Then
' project already loaded so just
' display the existing winpart
ShowWinPart(DirectCast(ctl, WinPart))
formToLoad.Dispose()
Return
End If
End If
Next...
Private Sub AddWinPart(ByVal part As WinPart)
AddHandler part.CloseWinPart, AddressOf CloseWinPart
part.BackColor = ToolStrip1.BackColor
MainFormPanel.Controls.Add(part)
Me.DocumentsToolStripDropDownButton.Enabled = True
ShowWinPart(part)
End Sub
In some cases I want to send a parameter to the Winpart control but am unsure of the best way to accomplish this. I realize that this is mostly a .NET question but I know other are using the winpart design and likely have a solution implemented. My first instinct is to go with an optional parameter in ShowSelectedForm but after reading about the use of optinal parameters I think this is poor design.
I have created a winpart control which contains the reportviewer control for a specific report. All works well for the single report but now I I need to make this control generic so I can use a single winpart control for all my reports. This control will accept a report name and then based on this name will aquire the correct datasoure, perform binding etc. I am unsure how to add the report name parameter in this case.
Any advice is truly appreciated.